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+1 || j==n+i-1 || j==i-n+1 || j==(n*3-i)-1)
cout<<"*";
else if(j<=n-i||j>=n+i || j<=i-n || j>=(n*3)-i)
cout<<" ";
else
cout<<".";
}
cout<<endl;
}
getch();
}
/*
Output
Enter N : 5
*
*.*
*...*
*.....*
*.......*
*.....*
*...*
*.*
*
*/
#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+1 || j==n+i-1 || j==i-n+1 || j==(n*3-i)-1)
cout<<"*";
else 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