Problem Statement
Write a C program to sum of digits in an integer.
Solution
#include<stdio.h> //Header File
int main() //Main function
{
int num,sod=0,digit;
scanf("%d",&num); //Reading Input
while(num>0)
{
digit=num%10; //Getting Each digit from an input
sod=sod+digit; //Adding the digits
num=num/10;
}
printf("%d",sod); //Printing Output
return 0;
}
Input
12345
Output
15
Sum of digits c program |