C language

Find Sum Of Digit For Given Value By User.

This problem will calculate the sum of all digit in the value give by user.

#include<stdio.h>

void main()
{
    long long no,temp;
    int rem,sum=0;

    printf("\n\tEnter 5 to 6 digit number ");
    scanf("%lld",&no);

    temp=no;
    //printf("no=%ld",no);
    do
    {
        while(temp!=0)
        {
            rem=temp%10;
           //// printf("rem=%d\n",rem);
            sum=sum+rem;
            temp=temp/10;
        }
        //printf("\nsum %d",sum);
        temp=sum;
        sum=0;
       // printf("\ntemp=%ld",(temp/10));
    }while((temp/10)!=0);
    printf("\n\t_____________________________________");
    printf("\n\tSum %d\n",temp);

}

 

Leave a Reply

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