题解 | #水仙花数#

水仙花数

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

#include <stdio.h>

int main() {
    int a, b;
    while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to 
        int i=0;//遍历数字
        int n=0;//代替i进行计算
        int sum=0;
        int state=0;//记录状态,存在则为1,不存在则为0
        for(i=a;i<=b;i++)
        {
            sum=0;
            n=i;
            while(n)
            {
                sum+=(n%10)*(n%10)*(n%10);
                n/=10;
            }
            if(sum==i)
            {
                printf("%d ",i);
                state=1;
            }
        }
        if(state==0)
        {
            printf("no\n");
        }
    }
    return 0;
}

全部评论

相关推荐

谁知道呢_:要掉小珍珠了,库库学三年,这个结果
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务