i am working on a logic by making diamonds and rectangle or triangle by using a single for loop. after working and thinking so much i am successfull to draw a rectangle or a diamond or a triangle with a single for loop. here is my code.
#include <iostream>
usingnamespace std;
int main ()
{
constint size = 15;
int lefter = (size/2);
int righter = (size/2);
int looper = size*size;
int k=0;
for(int i = 1;i<=looper;i++)
{
if(!(k<=lefter||k>=righter)) //area of work
cout<<"!";
else
cout<<"-";
k = i%size;
if(k == 0)
{
if( i<looper/2)
{
lefter--;
righter++;
cout<<endl;
}
else
{
cout<<endl;
lefter++;
righter--;
}
}
}
system("PAUSE");
}
this code will creat a diamond shape. i want to creat a rectangle within this diamond. anybody here to guide me ? the work in first if condition will give me the ruslt