Pages

Tuesday, January 14, 2014

[H]. (g) If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits.

void main()
{
 int a, b, c, d, e, sum;
 long num;
 clrscr();
 printf("Enter Five Digit Number : ");
 scanf("%ld",&num);
 e=num%10;
 num=num/10;
 d=num%10;
 num=num/10;
 c=num%10;
 num=num/10;
 b=num%10;
 num=num/10;
 a=num%10;
 sum=a+b+c+d+e;
 printf("Sum=%d",sum);
 getch();
}

No comments:

Post a Comment