-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern6.cpp
More file actions
53 lines (46 loc) · 911 Bytes
/
pattern6.cpp
File metadata and controls
53 lines (46 loc) · 911 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
/*PROGRAM TO PRINT PATTERN
1
2 3 2
3 4 5 4 3
2 3 2
1
FOR N=5 AND SO ON */
#include<iostream>
using namespace std;
int main()
{
int n,row,col,k,j;
cin>>n;
row=1,k=1,j=1;
while(row<=n)
{
col=1;
while(col<=n)
{
if(col<=n/2+1-k || col>=n/2+1+k)
cout<<" ";
else
{
cout<<j;
if(col<n/2+1)
j=j+1;
else
j=j-1;
}
col=col+1;
}
cout<<endl;
row=row+1;
if(row<=n/2+1)
{
k=row;
j=row;
}
else
{
k=n+1-row;
j=n+1-row;
}
}
return 0;
}