forked from panthji/cppprograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchandan4
More file actions
43 lines (35 loc) · 759 Bytes
/
chandan4
File metadata and controls
43 lines (35 loc) · 759 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
// C++ code to demonstrate star pattern
#include <iostream>
using namespace std;
// Function to demonstrate printing pattern
void pypart2(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 - 2;
// 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 = 10;
// Function Call
pypart2(n);
return 0;
}