大写字母Y

自从小蓝学会编程之后,他酷爱用编程的方式写字。你能帮助他写出字母"Y"吗?

输入:整数10(1<n<50)。

输出:输出高度为2n-1行的大写字母"Y"

 

 

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int t=2*n-1;
    for(int i=1;i<n;i++){
        for(int j=1;j<=i-1;j++) cout<<" ";
        for(int j=1;j<=t;j++){
            if(j==1||j==t) cout<<"*";
            else cout<<" ";
        }
        t-=2;
        cout<<endl;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)
            if(j==n)cout<<"*";
            else cout<<" ";
            cout<<endl;
    }
    return 0;
}

 

posted @ 2022-08-09 07:14  Hi,小董先生  阅读(1504)  评论(0)    收藏  举报