题解 | 数字之和

数字之和

https://www.nowcoder.com/practice/ae759916631f4711a90c4d4d9657f4b0

#include <iostream>
using namespace std;

int func(long long n) {
    int res = 0;
    while (n) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

int main() {
    long long n;
    while (cin >> n) {
        cout << func(n) << " " << func(n * n) << endl;
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
牛客21331815...:像我一投就pass,根本不用焦虑泡池子
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务