输出所有水仙花数,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。
写出该问题的C语言代码
#include <stdio.h>
#include <math.h>
void main()
{
int a,b,c,n=100;
while(n<1000) // 求的3位数的水仙花数 如果不够 你在自己改下就OK了
{
a=n/100;
b=n/10%10;
c=n%10;
if(n==(pow(a,3))+(pow(b,3))+(pow(c,3)))
{
printf("%d",n);
printf("\n");
}
n++;
}
}