forked from dev0victor/Hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern_Triangle.cpp
More file actions
49 lines (39 loc) · 772 Bytes
/
Pattern_Triangle.cpp
File metadata and controls
49 lines (39 loc) · 772 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
47
48
//Pattern :
// *
// ***
// *****
// *******
#include <iostream>
using namespace std;
// Function to demonstrate printing pattern
void triangle(int n)
{
// number of spaces
int k = 2 * n - 2;
// Outer loop to handle number of rows
// n in this case
for (int i = 0; i < n; i++) {
// Inner loop to handle number spaces
// values changing acc. to requirement
for (int j = 0; j < k; j++)
cout << " ";
// Decrementing k after each loop
k = k - 1;
// Inner loop to handle number of columns
// values changing acc. to outer loop
for (int j = 0; j <= i; j++) {
// Printing stars
cout << "* ";
}
// Ending line after each row
cout << endl;
}
}
// Driver Code
int main()
{
int n = 5;
// Function Call
triangle(n);
return 0;
}