题解 | #水仙花数#

水仙花数

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

#include <stdio.h>

int main() 
{
    int m=0,n=0;
    while((scanf("%d%d",&m,&n))!=EOF)
    {
        int count=0;
        for(int i=m;i<=n;i++)
        {
            int s=i,sum=0,o;
            while(s>0)
            {
                o=s%10;
                sum=sum+o*o*o;
                s/=10;
            }
            if(sum==i)
            {
                printf("%d ",sum);
                count++;
            }
        }
        if(count==0)
        printf("no\n");
        else
         printf("\n");
    }
    return 0;
}

全部评论

相关推荐

逆流河上万仙退:我觉得佬没必要 学历在这里 去了也不会对履历有很大提升 只是有可能让自己更熟练 是我的话会更倾向于找暑期或者中大厂日常
查看13道真题和解析
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务