Thursday , February 22 2018
Home / c-program / C Program – Sum of digits of given number till single digit

C Program – Sum of digits of given number till single digit

C Program to print the sum of digits till single digit.

Sum of Digits Till Single Digit :


#include<stdio.h> 
int main(void) 
{ 
    long num; 
    int dig,sum; 
    printf("Enter any number : "); 
    scanf("%ld",&num); 
    printf("%ld-> ",num); 
    do 
    { 
        sum = 0;  
        while(num!=0)  
        { 
            dig=num%10; 
            sum+=dig; 
            num/=10; 
        } 
        printf("%d-> ",sum); 
        num=sum; 
    }while(num/10!=0);     
    return 0; 
}

Enter any number : 586596
586596-> 39-> 12-> 3

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 – Addition of two Matrices Example

C Program to Addition of two Matrices. Addition of two Matrices : Happy Learning 🙂

Leave a Reply

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