Files
python/TangDou/ShuGen.cpp

30 lines
471 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
// 数根
// 暴力法
void func1(int n) {
while (true) {
int sum = 0;
while (n) {
sum += n % 10;
n /= 10;
}
n = sum;
if (n < 10) break;
}
cout << n << endl;
}
// 公式法
void func2(int n) {
cout << (n % 9 ? n % 9 : 9) << endl;
}
int main() {
int n;
cin >> n;
func1(n);
func2(n);
return 0;
}