C language: 3 methods; 0 ~ All "Daffodils" between 999 and output.
Method 1:
# Include <stdio. h> int main () {int I, j, k, n; printf ("daffodils:", n); for (n = 100; n <1000; n ++) {I = n/100; j = n/10-i * 10; k = n % 10; if (n = I * I + j * j + k * k) printf ("% d \ n", n) ;}return 0 ;}
Output result: daffodils: 153 370 371 407 Press any key to continue Method 2:
# Include <stdio. h> # include <math. h> int main () {int I, m, sum; for (I = 100; I <1000; I ++) {sum = 0; m = I; do {sum = sum + pow (m % 10, 3); // pow (a, B) indicates that the power of B of a is m = m/10 of double type ;} while (m! = 0); if (sum = I) printf ("% d", I);} printf ("\ n"); return 0 ;}
Running result: 153 370 371 407 Press any key to continue method 3:
# Include <stdio. h> int main () {int I, j, k, n; printf ("daffodils:", n); for (n = 100; n <1000; n ++) {I = n/100; j = (n-I * 100)/10; k = n-I * 100-j * 10; if (n = I * I + j * j + k * k) printf ("% d \ n", n) ;}return 0 ;}
Result: daffodils: 153 370 371 407