输出100-999中的所有水仙花数。若3位数ABC满足ABC=A^3+B^3+C^3,则称其为水仙花数。
#include "stdafx.h"
#include <math.h>
int main(int argc, char* argv[])
{
int a, b, c, abc;
for (abc = 100; abc<= 999; abc++) {
a = abc/100;
b = abc%100/10;
c = abc%10;
if(abc == pow(a,3) + pow(b,3) + pow(c,3))
printf("%d\n", abc);
}
return 0;
}