Sunday, April 24, 2016

Published April 24, 2016 by with 0 comment

UVA 11332 - Summing Digits : Solution

#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;
}
      edit

0 comments:

Post a Comment