Thursday 3 January 2008

Find sum of the digit of number using c program




C program to calculate or find sum
of each digits of a given number





#include


int main(){

int num,sum=0,r;

printf("\nEnter
a number:");

scanf("%d",&num);

while(num){

r=num%10;

num=num/10;

sum=sum+r;

}

printf("sum=%d",sum);

return 0;

}



If
you have any queries in above code find
sum of the digit of number using c program, please share us.

No comments:

Post a Comment