求水仙花数。所谓水仙花数。是指一个三位数ABC,a^+b^+c^=abc,则abc是水仙花数。

来源:百度知道 编辑:UC知道 时间:2024/07/16 23:36:15

#include<stdio.h>
void main()
{
int m,n,p,temp1,temp2,a,b,c;
int i,l;
while(EOF!=scanf("%d%d",&m,&n))
{
l=0;
p=n-m;
for(i=0;i<=p;i++)
{
temp1=m+i;

a=temp1%10;
temp2=temp1/10;
b=temp2%10;
c=temp2/10;

if(temp1==(a*a*a+b*b*b+c*c*c)&&l==0)
{
printf("%d",temp1);
l++;
continue;
}
if(temp1==(a*a*a+b*b*b+c*c*c))
{
printf(" %d",temp1);
l++;
}
}
if(l==0)
{
printf("no\n");
}
else
printf("\n");
}
}

#include "stdio.h"
main()
{int a,x,y,z;
for(a=100;a<=999;a++)
{x=a/100;
y=(a-x*100)/10;
z=a-x*100-y*10;
if(a==x*x*x+y*y*y+z*z*z)printf("%d\n",a);
}