题解 | #水仙花数#

水仙花数

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

#include <stdio.h>
int pow(int n) {
    return n * n * n;
}
void func(int n, int* sum) {
    if (n > 10)
        func(n / 10, sum);

    *sum += pow(n % 10);

}  //递归处理各立方相加
int main() {
    int m, n, temp = 0, flag = 0;
    int sum = 0;
    scanf("%d%d", &m, &n);
    for (int i = m; i <= n; i++) {
        temp = i;
        func(i, &sum);
        if (sum == temp) {
            printf("%d ", sum);
            flag = 1;
            sum = 0;
        }
        sum = 0;
    }
    if (flag != 1)
        printf("no");
}



}int main() {int m, n, temp = 0, flag = 0;int sum = 0;scanf("%d%d", &m, &n);for (int i = m; i <= n; i++) {temp = i;func(i, &sum);if (sum == temp) {printf("%d ", sum);flag = 1;sum = 0;}sum = 0;}if (flag != 1)printf("no");}

全部评论

相关推荐

11-02 09:49
已编辑
货拉拉_测试(实习员工)
热爱生活的仰泳鲈鱼求你们别卷了:没事楼主,有反转查看图片
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务