注意事项: 表达得非常乱,代码也很乱,就不贴了;


解题思路:  应用for循环;解决题目要求;

for( z=0; z<b; z++)  // 重复数嵌套行数

{

     int c; //判断当前是否是中间行 

     int d=0; // *号前的空格和 ,每次输出一行加 s,到

                                                                                X   X

                                                                                 X X

                                                                                  X   这里的时候,s 就                                                                                                                                                             s=-s;

                                                                                                             d += s;

                                                                                                             l = -l;

                                                                                                        就d就

                                                                                 X X

                                                                                X   X  

     int s=1; //空格数 

     int k = a;// 方便计算两个*号间的间隔   

     int l = 2; // 下边的*号 

  X

 X X

X   X

     int v =1;

    for( i=0; i<a; i++)

    {

         int j;

        

         c = k-l; // *  *  中间的空格个数等于 总行数-2 

         k -= l;  

         使用if判断,c是否大于0;是 则再判断v是否输出

                                                                                X   X

                                                                                 X X

                                                                                  X

                                                                                 X X

                                                                                X   X  这行

                                                                                 X X

                                                                                  X

                                                                                 X X

                                                                                X   X

        因为重复数。

    

for( j = d; j>0;j--)

{

printf(" ");            输出空格 X     X  

}


    }

}

注意事项:  输入判断:

while( !(N<=15))

{

scanf("%d",&N);

}

for( h=0; h<N; h++ )

{

scanf("%d%d",&a,&b);

while(!(a>=3 && a<=39 && a%2!=0) || !(b>=1 && b<=20)) //判断a,b是否符合要求  !取非 

{

scanf("%d%d",&a,&b);

}



参考代码:

点赞(0)
 

0.0分

0 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论