输出所有水仙花数
“水仙花数”(parcissus number)是指一个3位数,其各位数字的立方和相加等于其本身。
如:153是一个水仙花数,153=1^3+ 5^3 +3^3
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int i, a, b;
int x, y, z;
printf("请输入区间下限和上限:\n");
scanf("%d%d", &a, &b);
printf("水仙花数是:");
for ( i = a; i < b; i++)
{
x = i / 100;//百位
y = i / 10 - x * 10;//十位
z = i % 10;//个位;
if (i == x * x * x + y * y * y + z * z * z)
{
printf("%4d",i);
}
}
printf("\n");
system("pause");
return 0;
}