forked from DHEERAJHARODE/Hacktoberfest2024-Open-source-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspiralpattern.cpp
60 lines (43 loc) · 958 Bytes
/
spiralpattern.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
#include <bits/stdc++.h>
using namespace std;
void pattern(int value)
{
int row = 2 * value - 1;
int column = 2 * value - 1;
int arr[row][column];
int i, j, k;
for (k = 0; k < value; k++) {
j = k;
while (j < column - k) {
arr[k][j] = value - k;
j++;
}
i = k + 1;
while (i < row - k) {
arr[i][row - 1 - k] = value - k;
i++;
}
j = column - k - 2;
while (j >= k) {
arr[column - k - 1][j] = value - k;
j--;
}
i = row - k - 2;
while (i > k) {
arr[i][k] = value - k;
i--;
}
}
for (i = 0; i < row; i++) {
for (j = 0; j < column; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
}
int main()
{
int n = 5;
pattern(n);
return 0;
}