Monday, September 10, 2018

Print Diamond Pattern

// Program to print Diamond Pattern
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int num; // To input number of lines
cout<<"Enter Number "; cin>>num;
int r,c,sp;
for(r=1; r<=num; r++) {
for(sp=1;sp<=num-r;sp++) cout<<"  ";
for( c=1 ; c<=2*r-1; c++)
{
cout<<"@ "; // will print * in a single line
}
cout<<"\n"; // At end of inner loop next line will
// come in a new line
}
for(r=num-1; r>=1; r--) {
for(sp=1;sp<=num-r;sp++) cout<<"  ";
for(c=1 ; c<=2*r-1; c++)
{
cout<<"@ "; // will print * in a single line
}
cout<<"\n"; // At end of inner loop next line will
// come in a new line
}
getch();
}

No comments:

Post a Comment