In this program, the user is ask to enter the number, then the sum of digits is calculated and displayed on the console. For example, if the user enter 1234 then the sum of digits will be 1 + 2 + 3 + 4 = 10
#include<stdio.h>
#include<conio.h>
void main()
{
int num, sum=0;
//clrscr();
printf("Enter a number: ");
scanf("%d", &num);
while(num!=0)
{
sum = sum + (num % 10);
num = num / 10;
}
printf("Sum of digits = %d", sum);
getch();
}
Enter a number: 4562
Sum of digits = 17