
什麼是水仙數?
「水仙花數」是指一個3位數,其各位數字的立方和等於該數本身。
實作程式碼:
#include<stdio.h>
int main()
{
int a,b,c;
for(int i=100;i<=999;i++)
{
a=i/100; //百位数
b=(i/10)%10; //十位数
c=i%10; //个位数
if(a*a*a+b*b*b+c*c*c==i)
printf("%d\n",i);
}
return 0;
}輸出結果如下:

#推薦教學:c語言教學
以上是c語言實現輸出所有的水仙花數的詳細內容。更多資訊請關注PHP中文網其他相關文章!