- #include <stdio.h>
- int main() {
- printf("这是一个输出100-1000水仙花数的程序\n");
- /*个位,十位,百位*/
- int theUnit = 0, decade = 0, hundreds = 0;
- /*中间参数*/
- int middles = 0;
- for(int i = 100;i < 9000;i++){
- /*提取个位*/
- theUnit = i % 10;
- middles = i / 10;
- /*提取十位*/
- decade = middles % 10;
- /*提取百位*/
- hundreds = middles / 10;
- if((theUnit * theUnit * theUnit) + (decade * decade * decade) + (hundreds * hundreds * hundreds) == i){
- printf("你抓到了一个水仙花数:%d\n",i);
-
- }
- }
- return 0;
- }
复制代码
输出是
153
370
371
407
1000
1001
为什么会有1000和1001?
|
|