Can anyone tell me how to sketch shapes like square with empty space in a middle, diamond with empty space and without empty space, too, an arrow, separately, pointing all directions, an oval shape empty space and without empty, and all other by using nested for loop? Kindly guide me with its coding.
#include<iostream>
#include<cstdlib>
usingnamespace std;
int main()
{
int j,i,n;
cout<<"Enter the number of lines : ";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(j==1 || j==n || i==1 || i==n)
cout<<'A';
else
cout<<' ';
}
cout<<endl;
}
cout<<endl;
system("PAUSE");
}
i controls the line .for each line we have some characters that is controlled by j. the condition for square is
1) in first and last line print the character in all places.
for this i specify the condition if(i==1 || i==n)
2) in all other lines we have to put the character in first and last place only
for this i specify the condition if(j==1 || j==n)
3) for all lines between first and last we have to put space in the placed left by second condition.
for this i specify the condition else cout<<' ';