/*
The number of roots can be obtained by adding a number of digits to each digit. If the resulting number is a single number, then this number is the number root. If the result is a double-digit number or a number that includes more digits, add the numbers together. So go on until you get a count.
For example, for 24来 said, add 2 and 4 to get 6, because 6 is a single number, so 6 is the number of 24. For example, 39, add 3 and 9 to get 12, because 12 is not a number, so we have to add 1 and 2 together, and finally get 3, which is a single number, so 3 is the number of 39.
Input
A positive integer (less than 10 1000).
Output
A number, which is the number root of the input number.
Sample Input
24
Sample Output
6
*/
#include <stdio.h>
int main ()
{
Char a[3000];
int sum=0,i=0,fun=0,j;
Gets (a);
while (a[i]!= ')
{
sum+=a[i]-' 0 '; Converts a long string of strings to a data type that can be stored in int type
i++;
}
while (1)
{
fun=0;
if (sum==sum%10)
{
Fun+=sum;
Break
}
if (sum!=sum%10)
{while (sum)
{
fun+=sum%10;
SUM=SUM/10;
}
}
J=fun;
if (j!=j%10)
Sum=j;
Else
Break
}
printf ("%d", fun);
}
The main difficulty of this question is how to express the number of 10 of the 1000 square
1. Using each number in a single character space
2. The number of these numbers can be stored in the data of type int
3. Finally add up on the line.
Algorithm training first question