Pattern in C++

#include<iostream.h>
#include<conio.h>

void main()
{
int i, j, n;
clrscr();
cout<<"Enter N : ";
cin>>n;
cout<<endl;
for(i=1;i<n*2;i++)
{
  cout<<"\t";
  for(j=1;j<n*2;j++)
  {
     if(j<=n-i||j>=n+i || j<=i-n || j>=(n*3)-i)
cout<<".";
     else
cout<<"*";
  }
  cout<<endl;
}
getch();
}

/*
Output

Enter N : 5

....*....
...***...
..*****..
.*******.
*********
.*******.
..*****..
...***...
....*....

*/

No comments

Post your comments

Powered by Blogger.