Today, I am a little depressed. I want to solve the problem with two questions. I found this question and the result is .... Wa has been written for n times. At the beginning, we didn't take into account the large numbers. We wrote an integer to the end recursively, and then wa came down !! Later, I saw someone in discuss saying that it was written in strings. The result was wa for a long time. I couldn't help it. I looked at other people's code. I was dizzy! Ended with 0. I did not judge it directly .... A tragic day ~~~
Read the Code:
# Include <stdio. h>
# Include <string. h>
Int root (int x)
{
Int sum = 0;
While (X)
{
Sum + = x % 10; X/= 10;
}
If (sum <10) return sum;
Else return root (SUM );
}
Int main ()
{
Int X, I;
Char s [1001];
While (scanf ("% s", S )! = EOF)
{
If (! Strcmp (S, "0") break;
For (I = 0, x = 0; s [I]! = '\ 0'; I ++)
X + = s [I]-'0 ';
Printf ("% d \ n", root (x ));
}
Return 0;
}