题解 | #水仙花数#

水仙花数

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

#include <stdio.h>
#include<math.h>
int pdss(int x)
{
	int start = x;
	int num = 0; int tmp = 0;
	while (x)
	{
		tmp = x % 10;
		num += pow(tmp, 3);
		x = x / 10;
	}
	if (num == start)
		return 1;
	return 0;
}
void print(int x,int y)
{
    int i=0;int flag=1;
    for(i=x;i<=y;i++)
    {
        if(pdss(i))
        {
            flag=0;
            printf("%d ",i);
        }
    }
    if(flag==1)
    {
        printf("no");
    }
    printf("\n");
}
int main() {
    int a, b;
    while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 处理多个 case
        print(a,b);
       
    }
    return 0;
}

全部评论

相关推荐

吴offer选手:学到了,下次面试也放张纸在电脑上,不然老是忘记要说哪几个点
点赞 评论 收藏
分享
04-22 15:13
已编辑
Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务