题解 | #数字之和#
数字之和
https://www.nowcoder.com/practice/ae759916631f4711a90c4d4d9657f4b0
#include <iostream> using namespace std; int SUM(int n) { int sum = 0; while(n != 0) { //取模、取整 sum += n % 10; n /= 10; } return sum; } int main() { int a; while (cin >> a) { // 注意 while 处理多个 case cout << SUM(a) << " " << SUM(a*a) <<endl; } return 0; } // 64 位输出请用 printf("%lld")