水仙花数(daffodil)
输出100~999中的所有水仙花数。若3位数ABC满足,则称其为水仙花数。例如,所以153是水仙花数。
1 #include <stdio.h>
2
3 int
4 main()
5 {
6 int abc = 0;
7 int a = 0;
8 int b = 0;
9 int c = 0;
10
11 scanf("%d", &abc);
12
13 while ((abc < 100) || (abc > 999))
14 {
15 printf("input is wrong\n");
16 scanf("%d", &abc);
17 }
18
19 c = abc % 10;
20 b = abc % 100 / 10;
21 a = abc / 100;
22
23 printf("%d\t%d\t%d\n", a, b, c);
24
25 if (abc == a * a * a + b * b * b + c * c * c)
26 {
27 printf("%d is a daffodil\n", abc);
28 }
29 return 0;
30
31 }
~