三位數 abc,滿足 a³ + b³ + c³ = abc。1000 以內僅含三位數(100-999)。
#include
#include
int main() {
printf("1000 以內的水仙花數:\n");
for (int n = 100; n < 1000; n++) {
int a = n / 100; // 百位
int b = (n / 10) % 10; // 十位
int c = n % 10; // 個位
if (a*a*a + b*b*b + c*c*c == n) {
printf("%d ", n);
}
}
printf("\n");
return 0;
}
1000 以內的水仙花數: 153 370 371 407
pow() 呼叫。CSDN 部落格完整教學:C語言計算水仙花數