-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path14_pattern_and_star_2.cpp
53 lines (41 loc) · 1.17 KB
/
14_pattern_and_star_2.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
50
51
52
53
/*
Pattern Numbers & Stars - 2
Take as input N, a number. Print the pattern as given in the input and output section.
Input Format: Enter value of N
Constraints: 1 <= N < 10
Output Format: Print the pattern.
Sample Input: 7
Sample Output: 1******
12*****
123****
1234***
12345**
123456*
1234567
Explanation: There is no space between any two numbers. Catch the pattern for corresponding input and print them accordingly.
*/
#include<iostream>
using namespace std;
int main() {
int total_rows;
cin >> total_rows;
int nop = 1; // number of pattern in first row
int nos = total_rows-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--;
cout << endl;
}
return 0;
}