11332 - Summing Digits
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2307
f(n) = 1+2+3+4+5+6+7+8+9+2 = 47 f(f(n)) = 4+7 = 11 f(f(f(n))) = 1+1 = 2
一直重复做,直到是单位数
#include<stdio.h>
int main(){
long n,t,sum=0;
while(scanf("%ld",&n)!=EOF){
if(n==0)break;
while(n/10)是个位数,返回0;
{t=n; sum=0;
while(t/10)
{sum+=t%10;
t=t/10;
}
n=sum+t;
}
printf("%ld\n",n);
} return 0;
}