English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

only program pls

2006-10-28 22:58:29 · 2 answers · asked by srinivas r 1 in Computers & Internet Programming & Design

2 answers

What are "idviduals"?

If it's just to add two integers together it's too simple for words.

See below for a good help site.
http://www.cplusplus.com/doc/tutorial/

2006-10-28 23:02:39 · answer #1 · answered by jan 7 · 2 0

#include
#include

void main()
{
clrscr();
unsigned int number;
printf("ENter the number whose sum you wanted? ");
scanf("%d",&number);

unsigned int sum = 0;
unsigned int new_num = number;
while(new_num != 0)
{
sum = sum + (new_num % 10);
new_num = new_num/10;
}
printf("The sum of the digits in number %d is %d ",number,sum);
getch();
}

Logic is simple. You go on dividing the number by 10, till it gets to zero. And in this calculate sum by adding indivisual digits, by taking remainder of the number by 10.

2006-10-29 07:23:21 · answer #2 · answered by manoj Ransing 3 · 0 0

fedest.com, questions and answers