forked from sachin-nono/codingpractice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRhombusPattern.cpp
More file actions
64 lines (53 loc) · 818 Bytes
/
RhombusPattern.cpp
File metadata and controls
64 lines (53 loc) · 818 Bytes
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Pattern Rhombus
for N=3
1
2 3 2
3 4 5 4 3
2 3 2
1
*/
#include<iostream>
using namespace std;
int main()
{
int rows,i,j,k,l,m,n,o,a,b,c,x=0,y=1,z=1;
cout<<"Enter number of rows:";
cin>>rows;
for(i=1;i<=rows;i++)
{
for(j=1;j<=rows-i;j++) //for tabs
cout<<"\t";
for(k=y;k<=z;k++) //i'th row element (left upper half)
{
cout<<k<<"\t";
if(k==1)
goto lb;
}
a=z;
for(l=a-1;l>=i;l--)
cout<<l<<"\t"; //i'th row element (right upper half)
lb:
x++;
y++;
z+=2;
cout<<endl;
}
a=x-1;
b=y-1;
c=z-4;
for(m=rows-1;m>=1;m--)
{
for(j=rows;j>m;j--) //for tabs
cout<<"\t";
for(n=a;n<=c;n++)
cout<<n<<"\t"; //for left lower half
for(o=c-1;o>=a;o--)
cout<<o<<"\t"; //for right lower half
a--;
b--;
c-=2;
cout<<endl;
}
return 0;
}