中譯
#include "stdio.h" int f(int n) { int tmp = 0; while( n ) { if( n >= 10 ) tmp += n % 10; else tmp += n; n = n / 10; } if( tmp >= 10 ) return f(tmp); else return tmp; } int main() { int n; while (scanf(" %d",&n) != EOF && n ) { printf("%d\n",f(n)); } return 0; }
沒有留言:
張貼留言