题解 | #数字之和#

数字之和

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

#include <stdio.h>

void func(long x){
    char remain[10] = "0";
    int i = 0;
    while (x != 0){
        remain[i] = x % 10;
        i++;
        x /= 10;
    }
    int sum = 0;
    for (int j = 0; j < 10; ++j) {
        sum += remain[j];
    }
    printf("%d ", sum);
}

int main(){
    long num;
    while(scanf("%ld", &num) != EOF){
        func(num);
        func(num * num);
        printf("\n");
    }
    return 0;
}

全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务