输出所有的水仙花数。所谓水仙花数是一个3位的正整数,其各位数字的立方和等于这个数本身。 例如,153是水仙花数,因为1^3+5^3+3^3=153。 ^代表上标
锻炼取出某个数的某位数的能力
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
int i;
for(i=100;i<1000;i++)//遍历所有三位数
{
if(pow(i/100,3)+pow((i%100)/10,3)+pow(i%10,3)==i) //pow(a,n)等价于a^n pow函数储存于math.h中
printf("%d\n",i);
}
return 0;
}