Table of Contents

Sum of digits

Prgram to find the sum of digits of a number.
#include <conio.h> 
#include <studio.h>   
void main()    
{    
int n,sum=0,m;    
printf("Enter a number:");    
scanf("%d",&n);    

while(n>0)    
{    
m=n%10;    
sum=sum+m;    
n=n/10;    
}    
printf("Sum is=%d",sum);    
getch();

}   
Program Output

Enter the Number : 145

Sum is  10

English Hindi