#include <stdio.h>
#include <math.h>
int main()
{
int i = 0;
int sz = 0;
printf("請輸入查詢的範圍,即最大值 sz = ");
scanf("%d",&sz);
for(i=1; i<=sz; i++)
{
int count = 0;
int tmp = i;
int sum = 0;
while(tmp)
{
count++;
tmp=tmp/10;
}
tmp = i;
while(tmp)
{
sum += pow((tmp%10),count);
tmp /= 10;
}
if(sum == i)
{
printf("%d ", i);
}
}
return 0;
}
求出所有“水仙花數”並輸出
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.