C++ Program to display the pattern of diamond [DEVCPP/GCC]

PROGRAM

//Program to display the pattern of diamond!

# include <iostream>
using namespace std;

int main()
{
int rows,uh,lh,i,j,k;

cout<<"ENTER THE NUMBER OF ROWS:";
cin>>rows;

//Calculating the rows to be dedicated for the upper triangular part
uh=(rows/2)+1;  

       //Calculating the rows to be dedicated for the lower triangular part
       lh=(rows-uh);      

for(i=1;i<=uh;i++)          //Printing upper triangle
{
for(j=(uh-i);j>0;j--)
{
cout<<" ";
}
for(k=1;k<(2*i);k++)
{
cout<<"*";
}
cout<<endl;
}

for(i=lh;i>0;i--)               //Printing lower triangle
{
for(j=0;j<=(lh-i);j++)
{
cout<<" ";
}
for(k=1;k<(2*i);k++)
{
cout<<"*";
}
cout<<endl;
}

return 0;
}


OUTPUT

C++ Program to display the pattern of diamond with output

Share this

Related Posts

FIND US ON FACEBOOK!