9Google AdSense

11332 Summing digit

#include<stdio.h>


int main()
{
    long long int n,a,b,i,ary[100],sum;
     while(scanf("%ld",&n)==1)
     {
     if(n==0)
    break;
     do
     { sum=0;
     while(n!=0)
     {
    sum=sum+n%10;
    b=n/10;
    n=b;
     }
      n=sum;
     }while(sum>=10);
     printf("%ld\n",sum);
     }
     return 0;
}

No comments: