Given a number the task is to calculate the sum of digits.
Example: 253. 2+5+3 = 10.
C
#include <stdio.h>
int main()
{
int n=0,r=0,sum=0;
printf("Enter a number: ");
scanf("%d",&n);
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("Sum of digits is %d",sum);
return 0;
}C