今天第一次发布文章。
内容:打印空心三角形
输入#1
5
输出#1
* * * * * * * * * * * *
代码如下:
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,ss = 1;cin>>x;
for(int i = 1;i<=x;i++){
if(i == 1){
for(int j = 1;j<=x-1;j++)cout<<" ";
cout<<"*";
for(int j = 1;j<=x-1;j++)cout<<" ";
}
else if(i == x){
for(int j = 1;j<=x;j++)cout<<"* ";
}
else{
for(int j = 1;j<=x-i;j++)cout<<" ";
cout<<"*";
for(int j = 1;j<=ss;j++)cout<<" ";
cout<<"*";
ss+=2;
}
cout<<endl;
}
return 0;
}