C Program to find Sum of Digits of a given number Type 1
Program
#include<stdio.h>
void main()
{
int rem, num, sum = 0;
int temp;
printf("Enter a number to find sum of digits\n");
scanf("%d", &num);
temp = num;
while(num > 0)
{
rem = num % 10;
num = num / 10;
sum = sum + rem;
}
printf("Sum of digits of number %d is %d\n", temp, sum);
}
Output
Enter a number to find sum of digits
1784
Sum of digits of number 1784 is 20