0:22 AM midterm 2008-2009 Q3 |
program to calculate sum of digits of positive integer number
#include"stdio.h"
main()
{
int i, x, sum=0;
printf("enter number : ");
scanf("%d", &x);
for(i=1;x!=0;i++){
sum+=x%10;
x/=10;
}
printf("Sum = %d", sum);
getch();
return 0;
}
|
|
Total comments: 0 | |