A50851. 编程实现:大写字母Y程序命名:y.cpp自从小蓝学会编程之后,他酷爱用编程的方式写字厚。你能帮助他写出字母""吗?输入:整数n(1(n<50)。输出:输出高度为2n-1行的大写字母"Y".提示:第一行第一颗左侧无多余空格,每行最后一颗*后无多余空格。
填空题
困难
知识点
题目描述
编程实现:大写字母Y
程序命名:y.cpp
自从小蓝学会编程之后,他酷爱用编程的方式写字厚。你能帮助他写出字母""吗?
输入:整数n(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;
}答案解析
上一题
下一题