c program to add all the digits of a number.


#include<stdio.h>
#include<conio.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); 
return 0;


Output:

Enter a number:654
Sum is=15

Post a Comment

Previous Post Next Post