题解 | 水仙花数

水仙花数

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

#include <stdio.h>
#include <math.h>

int main() {
    int a, b;
    while (scanf("%d %d", &a, &b) != EOF) {
        int count = 0,res;
        for (int i = a; i <= b; i++) {
            res = pow(i%10,3)+pow(i/10%10,3)+pow(i/100,3);
            if(i==res){
                count++;
                printf("%d ",res);
            }
        }
        if(count==0){
            printf("no");
        }
        printf("\n");
    }
    return 0;
}

全部评论

相关推荐

03-10 21:11
武汉大学 运营
学不懂的那种:先天考公圣体
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务