Making any Shapes By Using Single For loop

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std;

int main ()

{
	 const int 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
Last edited on
Topic archived. No new replies allowed.