C PROGRAM TO FIND SUM OF DIGITS OF A NUMBER

 

  1. #include<stdio.h>  
  2.  int main()    
  3. {    
  4. int n,sum=0,m;    
  5. printf("Enter a number:");    
  6. scanf("%d",&n);    
  7. while(n>0)    
  8. {    
  9. m=n%10;    
  10. sum=sum+m;    
  11. n=n/10;    
  12. }    
  13. printf("Sum is=%d",sum);    
  14. return 0;  
  15. }   

Comments

Popular posts from this blog