C Program to Find Sum of Digit of a Given Number


Program


#include<stdio.h>
#include<conio.h>

int main()
{
	 long int number, sum=0, rem, original;
	 clrscr();
	 printf("Enter number: ");
	 scanf("%ld", &number);
	
	 original = number;
	
	 while(number!=0)
	 {
	  rem = number % 10;
	  sum = sum + rem;
	  number = number/10;
	 }
	 printf("Sum of Digit of %ld is %ld", original, sum);
	 getch();
	 return(0);
}

Output of the above program :

Enter number: 9999974 ↲ 
Sum of Digit of 9999974 is 56

Note: ↲ indicates enter is pressed.