-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern3.cpp
More file actions
77 lines (74 loc) · 1.14 KB
/
Pattern3.cpp
File metadata and controls
77 lines (74 loc) · 1.14 KB
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
71
72
73
74
75
76
77
// NUMERICAL PYRAMID
#include <iostream>
using namespace std;
/*
1
212
32123
4321234
543212345
*/
int p1(int N)
{
for (int i = 1; i <= N; i++)
{
int j;
for (j = 1; j <= (N - i); j++)
{
cout << " ";
}
int k = i;
for (; j <= N; j++)
{
cout << k--;
}
k = 2;
for (; j <= N + i - 1; j++)
{
cout << k++;
}
cout << endl;
}
return 0;
}
/*
1
232
34543
4567654
567898765
*/
int p2(int N)
{
int k = 0, count = 0, count1 = 0;
for (int i = 1; i <= N; ++i) {
for (int space = 1; space <= N - i; ++space) {
cout << " ";
++count;
}
while (k != 2 * i - 1) {
if (count <= N - 1) {
cout << i + k;
++count;
} else {
++count1;
cout << (i + k - 2 * count1);
}
++k;
}
count1 = count = k = 0;
cout << endl;
}
return 0;
}
int main()
{
int n;
cout << "Enter the rows:";
cin >> n;
p1(n);
cout << endl;
p2(n);
cout << endl;
return 0;
}