- //
- // main.c
- // HomeWork_09
- //
- // Created by 蒋伟 on 16/5/10.
- // Copyright (c) 2016年 蒋伟. All rights reserved.
- //
- #include <stdio.h>
- int main(int argc, const char * argv[]) {
- int num = 0;
- printf("水仙花数:\n");
- for(int i=100;i<=999;i++){
- int g = i%10;
- int s = i/10%10;
- int b = i/100;
- if(g*g*g+s*s*s+b*b*b == i){
- printf("%03d\t",i);
- num++;
- if(num%3 == 0){
- printf("\n");
- }
- }
- }
- printf("共%d个水仙花数!",num);
- return 0;
- }
复制代码
|
|