Code Competitions

Coding competition

Tuesday, 14 May 2013

Program to find the sum of digits upto single digit

#include<conio.h>
#include<stdio.h>
void main()
{
    int i,m=0,a,num,sum=0;
    clrscr();
    printf("\n\n\t\t Enter the number: ");
    scanf("%d",&num);
    while(num>9)
    {
        sum=0;
        while(num>0)
        {
            m=num%10;
            num=num/10;
            sum=sum+m;
        }
        num=sum;
    }
    printf("\n\n\t\t Sum of digits is: %d",sum);
    getch();
}

No comments:

Post a Comment