Example
Input
Input any number: 1234
Output
Sum of digits: 10
/**
* C program to find sum of its digits of a number
*/
#include <stdio.h>
int main()
{
int num, sum=0;
/* Input a number from user */
printf("Enter any number to find sum of its digit: ");
scanf("%d", &num);
/* Repeat till num becomes 0 */
while(num!=0)
{
/* Find last digit of num and add to sum */
sum += num % 10;
/* Remove last digit from num */
num = num / 10;
}
printf("Sum of digits = %d", sum);
return 0;
}
/*
Output :
Enter any number to find sum of its digit: 1234
Sum of digits = 10
*/