C Program to calculate sum of digits.

Sample Input 1 :

734

Sample Output 1 :

14 (7+3+4)

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#include<stdio.h> int main() { //write your code here }

Program or Solution

				
			
					
#include<stdio.h>
int main()
{
	int num,sum;
	scanf("%d",&num);
	while(num!=0)
	{
		sum+=num%10;
		num/=10;
	}
	printf("sum is %d",sum);
	return 0;
}
		
			
				
			

Program Explanation

refer video tutorial

Comments