Monday , September 25 2017
Home / c-program / C Program – Print the sum of digits of given number

C Program – Print the sum of digits of given number

C Program to print the sum of digits of given number.

Sum of Digits :


#include<stdio.h> 
int main(void) 
{ 
    int n,sum=0,rem; 
    printf("Enter a number to Calculate Sum: "); 
    scanf("%d",&n); 
    while(n>0) 
    { 
        rem = n%10;     
        sum+=rem; 
        n/=10;         
    } 
    printf("Sum of Digits=%d\n",sum); 
    return 0; 
}

Enter a number to Calculate Sum: 56489
Sum of Digits=32

Happy Learning 🙂

 

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Recommended

C Program to add elements of an array

How to add elements in an array using C Program. Add elements of an Array …

Leave a Reply

Your email address will not be published. Required fields are marked *