View Code of Problem 57

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<2*n-1;i++) {
		if(i<n){
			for(int j=0;j<n-i-1;j++)
				cout<<" ";
			for(int k=1;k<=i+1;k++)
				cout<<k;
			for(int l=i;l>0;l--)
				cout<<l;
			cout<<"\n";	
		} else {
			for(int j=i-n;j>=0;j--) 
				cout<<" ";
			for(int k=1;k<=2*n-1-i;k++)
				cout<<k;
			for(int l=2*n-2-i;l>0;l--)	
				cout<<l;
			cout<<"\n";	
		}

	}
	return 0;
}

Double click to view unformatted code.


Back to problem 57