C Program to find sum of digits in the given number

Previous
Next
#include <stdio.h>
int main()
{
	int num, sum=0;
	
	printf("Enter any number : ");
	scanf("%d", &num);
	
	while(num!=0)
	{
		sum += num % 10;
		num = num / 10;
	}
	printf("Sum of digits = %d", sum);
	return 0;
}
Previous
Next

Add Comment

Courses Enquiry Form