-
Notifications
You must be signed in to change notification settings - Fork 3
/
HollowDiamondPattern.cpp
70 lines (60 loc) · 1.09 KB
/
HollowDiamondPattern.cpp
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
65
66
67
68
69
70
/*
Hollow Diamond Pattern
Only odd values of N
for N=5
* * * * *
* * * *
* *
* * * *
* * * * *
*/
#include<iostream>
using namespace std;
int main()
{
int rows,a,c,x,i,j,k,l,m;
cout<<"Enter number of rows:";
cin>>rows;
x=rows/2+1;
a=x;
c=x;
for(i=1;i<=x;i++) //for upper half
{
if(i==1) //for first row only
for(j=1;j<=rows;j++)
cout<<"*\t";
else
{
for(k=1;k<a;k++) //*'s before tab
cout<<"*\t";
for(l=a;l<=c;l++) //for creating tabs
cout<<"\t";
for(m=c+1;m<=rows;m++) //*'s after tabs
cout<<"*\t";
a--;
c++;
}
cout<<endl;
}
a+=2;
c-=2;
for(i=x+1;i<=rows;i++) //for lower half
{
if(i!=rows)
{
for(k=1;k<a;k++) //*'s before tab
cout<<"*\t";
for(l=a;l<=c;l++) //for creating tabs
cout<<"\t";
for(m=c+1;m<=rows;m++) //*'s after tabs
cout<<"*\t";
}
else //for last row
for(j=1;j<=rows;j++)
cout<<"*\t";
a++;
c--;
cout<<endl;
}
return 0;
}