题解 | #Digital Roots#
Digital Roots
https://www.nowcoder.com/practice/cef727d0af33479c9fb4a9c120702414
#include <stdio.h> #include <string.h> int root(int number) { int cnt = 0; while (number != 0) { //获取各个位的数值 cnt += (number % 10); number /= 10; } if (cnt < 10) { return cnt; } else { return root(cnt); } } int main() { int number; while (scanf("%d", &number) != EOF) { printf("%d\n", root(number)); } return 0; }