-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_97Pattern.cpp
More file actions
46 lines (37 loc) · 966 Bytes
/
_97Pattern.cpp
File metadata and controls
46 lines (37 loc) · 966 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
// including required header files
#include <iostream>
using namespace std;
// main function
int main() {
// input number of rows from uesr
int num;
cout << "Enter the number of lines: ";
cin >> num;
// pritting pattern
cout << endl << "The pattern with " << num << " rows is" << endl << endl ;
for (int i = 1; i <= num; i++) {
for (int j = 1; j <= num - i; j++) {
cout << " ";
}
for (int k = i; k <= 2 * i - 1; k++) {
cout << k;
}
for (int l = 2 * i - 2; l >= i; l--) {
cout << l;
}
cout << endl;
}
for (int i = num - 1; i >= 1; i--) {
for (int j = 1; j <= num - i; j++) {
cout << " ";
}
for (int k = i; k <= 2 * i - 1; k++) {
cout << k;
}
for (int l = 2 * i - 2; l >= i; l--) {
cout << l;
}
cout << endl;
}
return 0;
}