|
发表于 2021-10-27 20:46:00
|
显示全部楼层
本楼为最佳答案
本帖最后由 jackz007 于 2021-10-27 22:04 编辑
【第3)题】:
- #include <stdio.h>
- int main(void)
- {
- int c , e ;
- for(c = 0 , e = 1000 ; e < 10000 ; e ++) {
- if((e / 100 + e % 100) * (e / 100 + e % 100) == e) {
- if(c && ! (c % 3)) printf("\n") ;
- if(c % 3) printf(" ") ;
- printf("%7d" , e) ;
- c ++ ;
- }
- }
- printf("\n") ;
- }
复制代码
编译、运行实况:
- D:\00.Excise\C>g++ -o x x.c
- D:\00.Excise\C>x
- 2025 3025 9801
- D:\00.Excise\C>
复制代码
【第4)题】:
- #include <stdio.h>
- int main(void)
- {
- int b , i , j , n ;
- scanf("%d", & n) ;
- for(i = 1 ; i <= 2 * n - 1 ; i ++) {
- b = (i > n) ? 2 * n - i : i ;
- for(j = n - b ; j > 0 ; j --) printf(" ") ;
- for(j = b * 2 - 1 ; j ; j --) printf("*") ;
- printf("\n") ;
- }
- }
复制代码
编译、运行实况:
D:\00.Excise\C>g++ -o x x.c
D:\00.Excise\C>x
5
*
***
*****
*******
*********
*******
*****
***
*
D:\00.Excise\C>x
6
*
***
*****
*******
*********
***********
*********
*******
*****
***
*
D:\00.Excise\C>x
7
*
***
*****
*******
*********
***********
*************
***********
*********
*******
*****
***
*
D:\00.Excise\C>
注意:以上图案与在 CMD 窗口中的视觉效果存在差异。 |
|