
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
char c;
cin>>n>>c;
for(int i=1;i<=(n/2+n%2);i++){//确定行数
if(i==1||i==(n/2+n%2)){//判断是否为首行或尾行
for(int j=0;j<n;j++)
{
cout<<c;//按首行尾行要求输出
}
cout<<endl;//换行
}else{
for(int j=1;j<=n;j++){
if(j==1||j==n){//是否为每行的首尾
cout<<c;
}else{
cout<<" ";
}
}
cout<<endl;//换行
}
}
}
这段C++代码用于输出由指定字符构成的矩形或梯形图案,根据输入的行数和字符,程序会打印出首行和尾行全为字符,中间行只有首尾为字符的图案。
1028

被折叠的 条评论
为什么被折叠?



