-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq26.cpp
38 lines (33 loc) · 787 Bytes
/
q26.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
/* WAP to make a number pyramid using friend function
* 1
* 2 2
* 3 3 3*/
#include <iostream>
using namespace std;
class Pattern {
public:
int rows, start_digit;
friend void display_pattern(Pattern p);
};
void display_pattern(Pattern p) {
int line_limit = 2 * p.rows;
int char_start = line_limit / 2;
for (int i = 0; i < p.rows; i++) {
int char_count = 0;
while (char_count < char_start - i) {
cout << " ";
char_count++;
}
for (int j = 0; j <= i; j++) {
cout << p.start_digit + i << " ";
}
cout << endl;
}
}
int main() {
Pattern triangle;
triangle.rows = 5;
triangle.start_digit = 1;
display_pattern(triangle);
return 0;
}