Monday, May 7, 2018

Write a C program to find the Sum of the digits of a given number.




#include<stdio.h>
int main()
{
int n,i,s=0,r;
printf("Enter A Number : ");
scanf("%d",&n);
while(n>0)
{
r=n%10;
n=n/10;
s=s+r;
}
printf("Sum of digits : %d",s);
return 0;
}



OUTPUT:

Enter A Number : 4532

Sum of digits : 14

0 comments: