View Code of Problem 53

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n==1)
	cout<<"*"<<endl;
	else
	{
			for(int i=1;i<=n;i++)//打印上半部分 
	{
		for(int j=1;j<=n-i;j++){
			cout<<" ";
		}
		for(int j=1;j<=2*i-1;j++){
			cout<<"*";
		}
		cout<<endl;
		
	}
	for(int i=n-1;i>=1;i--)//打印下半部分 
	{
		for(int j=1;j<(n-i+1);j++){
			cout<<" ";
		}
		for(int j=2*(i-1)+1;j>=1;j--){
			cout<<"*";
		}
		cout<<endl;
		
	}
	 } 

	return 0;
} 

Double click to view unformatted code.


Back to problem 53