pattern printing in c/c++-
ganesha pattern printing-
Given the number of rows and columns, print the corresponding swastika pattern using loops.
Note : The number of rows and columns should be same and an odd number. This will generate a perfect swastika pattern.
Input : row = 7, column = 7 Output: * * * * * * * * * * * * * * * * * * * * * * * * *
using namespace std;
int main() {
int n,star,space,i=0,row=1;
cin>>n;
star=(n/2)+1;
space=(n/2)-1;
for(row=1;row<=1;row++)
{
cout<<"*";
for(i=1;i<=space;i++)
{
cout<<" ";
}
for(i=1;i<=star;i++)
{
cout<<"*";
}
cout<<endl;
}
while(row<=(n/2))
{
cout<<"*";
for(i=1;i<=space;i++)
{
cout<<" ";
}
cout<<"*"<<endl;
row++;
}
for(i=0;i<n;i++)
{
cout<<"*";
}
cout<<endl;
int space1=space;
space=space+1;
while(row<n-1)
{
for(i=0;i<space;i++)
{
cout<<" ";
}
cout<<"*";
for(i=0;i<space1;i++)
{
cout<<" ";
}
cout<<"*"<<endl;
row++;
}
for(i=0;i<=row/2;i++)
{
cout<<"*";
}
for(i=0;i<space1;i++)
{
cout<<" ";
}
cout<<"*";
return 0;
}
Comments
Post a Comment