Print Diamond Shape in C++

Code:

#include<iostream>
using namespace std;
int main()
{
	int i,j,k,n;
	cout<<"Enter Number : ";
	cin>>n;
	cout<<"\n\n";
	for(i=1;i<=n;i++)
	{
		for(k=n;k>=i;k--)
		{
			cout<<" ";
		}
		for(j=1;j<=(2*i-1);j++)
		cout<<"*";
		cout<<endl;
	}
		for(i=n;i>=1;i--)
	{
		for(k=n;k>=i;k--)
		cout<<" ";
		for(j=1;j<=(2*i-1);j++)
		cout<<"*";
		cout<<endl;
	}
}

Output:

Enter Number : 6


      *
     ***
    *****
   *******
  *********
 ***********
 ***********
  *********
   *******
    *****
     ***
      *

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *