Sunday, April 24, 2016

UVA 11332 - Summing Digits : Solution

Unknown
#include <stdio.h>
int main()
{
    int n,ans;
    while (scanf("%d",&n) && n!=0)
    {
        ans=0;
        while (n)
        {
            ans+=(n%10);
            n=n/10;
        }
        while (ans>9)
        {
            ans=(ans/10)+(ans%10);
        }
        printf("%d\n",ans);
    }
    return 0;
}

Unknown

Studying at Shahjalal University of Science and Technology, Sylhet.

0 comments:

Post a Comment

Coprights @ 2016,