-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2Problem1.cpp
58 lines (51 loc) · 1.06 KB
/
day2Problem1.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
54
55
56
57
58
/*
Problem statement 1
Write a program to print the following pattern
Test case 1
Input
4
Output
1*2*3*4*17*18*19*20
--5*6*7*14*15*16
----8*9*12*13
------10*11
Test case 2
Input
3
Output
1*2*3*10*11*12
--4*5*8*9
----6*7
Note: Each hyphen represents one space
*/
#include<iostream>
using namespace std;
int main(){
int n;
cin >>n;
int last = n*(n+1); // last number
int a = 1;
for(int i = 1;i<=n;i++){
if(i !=1)
for(int j = 1;j<=i;j++){
cout <<" ";
}
for(int j = i;j<=n;j++){
cout << a++ <<"*";
}
int temp =a;
for(int j = i;j<=n;j++){
if(j == i){
cout <<"*"<< last - temp + 2;
temp--;
}
else{
cout <<"*"<< last - temp + 2;
temp--;
}
}
cout <<endl;
}
}
// cout <<"*"<< last - temp + 2;
// cout << "("<<last<<"-" << temp-2 <<")";