-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path13_pattern_and_star_1.cpp
49 lines (38 loc) · 1.12 KB
/
13_pattern_and_star_1.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
39
40
41
42
43
44
45
46
47
48
49
/*
Pattern Numbers & Stars - 1
Take as input N, a number. Print the pattern as given in output section for corresponding input.
Input Format: Enter value of N
Output Format: All numbers and stars are Space separated
Sample Input: 5
Sample Output: 1 2 3 4 5
1 2 3 4 *
1 2 3 * * *
1 2 * * * * *
1 * * * * * * *
Explanation: Catch the pattern for the corresponding input and print them accordingly.
*/
#include<iostream>
using namespace std;
int main() {
int total_rows;
cin >> total_rows;
int nop = total_rows; // number of pattern in first row
int nos = -1; // number of star in first row
for(int row=1; row<=total_rows; row++){
int cop; // counter of pattern
int cos; // counter of star
// print number pattern
for(cop=1; cop<=nop; cop++){
cout << cop << " ";
}
// print stars
for(cos=1; cos<=nos; cos++){
cout << "*" << " ";
}
// for next iterations
nop--;
nos += 2;
cout << endl;
}
return 0;
}