move to repo.or.cz
[letusc.git] / ch1 / exercises / ex7.c
blob5940dd71db6178cc14ea3efa28b1b32dc77ae242
1 /*calculate the sum of digits in a 5 digit number*/
3 #include<stdio.h>
5 int main()
7 long num;
8 int sum;
11 printf("Enter the five digit number: ");
12 scanf("%ld",&num);
14 sum = 0;
16 sum = sum + (num%10);
17 num=num/10;
19 sum=sum+(num%10);
20 num = num/10;
22 sum=sum+(num%10);
23 num = num/10;
25 sum = sum+(num%10);
26 num = num/10;
28 sum = sum+(num%10);
29 num = num/10;
31 printf("The sum is %d\n",sum);
33 return 0;