Calculate the sum of digits of the number
C program to find the sum of digits of the number.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int num,digit,sum=0;
printf("Enter a number\t:");
scanf("%d",&num);
while(num > 0)
{
digit = num % 10;
sum = sum + digit;
num = num/10;
}
printf("Sum of the digits is %d",sum);
getch();
}
Output
Enter a number :5465
Sum of the digits is 20