题解 | #X形图案#

X形图案

http://www.nowcoder.com/practice/83d6afe3018e44539c51265165806ee4

#include<iostream>
using namespace std;
int main()
{
int a;
    while(cin>>a)
    {
       for(int i=1;i<=a;i++)
       {
           for(int j=1;j<=a;j++)
           {
               if(i==j)
                   cout<<'*';
               else if(j==a-i+1)
                   cout<<'*';
               else
                   cout<<' ';
           }
               cout<<endl;
       }
    }
    return 0;
}
```在打印这种复杂图形时可以用两个for循环,并将这两个循环想象成一个直角坐标系,再用几个条件语句去画图形
全部评论
这个思路很好
点赞 回复 分享
发布于 2023-02-25 10:53 广东

相关推荐

评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务