-
Notifications
You must be signed in to change notification settings - Fork 3
/
pattern_97.cpp
54 lines (42 loc) · 1.07 KB
/
pattern_97.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
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter the number of rows: ";
cin >> n;
// Print the top half of the pattern
for (int i = 1; i <= n; i++) {
// Print spaces
for (int j = 1; j <= n - i; j++) {
cout << " ";
}
// Print increasing numbers
for (int k = i; k <= 2 * i - 1; k++) {
cout << k;
}
// Print decreasing numbers
for (int l = 2 * i - 2; l >= i; l--) {
cout << l;
}
// Move to the next line
cout << endl;
}
// Print the bottom half of the pattern
for (int i = n - 1; i >= 1; i--) {
// Print spaces
for (int j = 1; j <= n - i; j++) {
cout << " ";
}
// Print increasing numbers
for (int k = i; k <= 2 * i - 1; k++) {
cout << k;
}
// Print decreasing numbers
for (int l = 2 * i - 2; l >= i; l--) {
cout << l;
}
// Move to the next line
cout << endl;
}
return 0;
}