-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_patteren_palindrome.cpp
98 lines (88 loc) · 1.51 KB
/
04_patteren_palindrome.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
using namespace std;
int main(){
int n;
cout<<"enter the no of the rows:";
cin>>n;
// Pattern:01
// 1
// 121
// 12321
// 1234321
// 123454321
// for(int i=1; i<=n; i++){
// // space
// for(int j=n-i; j>=1; j--){
// cout<<" ";
// }
// for(int j=1;j<=i; j++){
// cout<<j;
// }
// for(int j=i-1; j>=1; j--){
// cout<<j;
// }
// cout<<endl;
// }
// int i=1;
// while(i<=n){
// // space:
// int space=n-i;
// while(space){
// cout<<" ";
// space--;
// }
// // First part of the triangle:
// int j=1;
// while(j<=i){
// cout<<j;
// j=j+1;
// }
// // Third triangle:
// // int k=1;
// // while(k<=i){
// // cout<<i-k+1;
// // k=k+1;
// // }
// // 2nd approach;
// int start=i;// for even
// int start=i-1;// for odd
// while(start){
// cout<<start;
// start=start-1;
// }
// cout<<endl;
// i=i+1;
// }
// int i=1;
// while(i<=n){
// int j=n-i+1;
// while(j){
// cout<<j;
// j--;
// }
// cout<<endl;
// i=i+1;
// }
//
// 1234554321
// 1234**4321
// 123****321
// 12******21
// 1********1
for(int i=n; i>=1; i--){
for(int j=1; j<=i; j++){
cout<<j;
}
for(int j=n-1; j>=i; j--){
cout<<"*";
}
for(int j=n-1; j>=i; j--){
cout<<"*";
}
for(int j=i; j>=1; j--){
cout<<j;
}
cout<<endl;
}
return 0;
}