今天分享个程序-输出0到999之间的水仙花数
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int i,a,b,c=0;
for (i = 100; i <= 999; i++)
{
a = i / 100;
b = i / 10 % 10;
c = i % 10;
if (pow(a, 3) + pow(b, 3) + pow(c, 3) == i)
{
printf("%d\t",i);
}
}
system("pause");
return 0;
}
严格来说只有3位数才可以是水仙花数,所以应该是求100到999的水仙花数!