Sunday, 13 November 2011

If a five-digit number is input through the keyboard ,write a program to calculate the sum of its digit?

/*Sum of  Digit of  a Number*/
#include
#include
void main()
{
int number,sum=0;
clrscr();
printf("Enter the Number you want to Sum its digit:");
scanf("%d",&number);
/*we use while loop and '%' to separate a number*/
printf("Sum of its digit is:");
while(number>0)
{
sum=sum+(number%10);
number=number/10;//update number
}
printf("%d",sum);
getch();
}

No comments:

Post a Comment