-
Notifications
You must be signed in to change notification settings - Fork 0
/
11_palindromic_pattern.cpp
94 lines (87 loc) · 1.6 KB
/
11_palindromic_pattern.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
// 11. palindromic pattern
#include<bits/stdc++.h>
using namespace std;
int main()
{
int row;
cout<<"row: ";
cin>>row;
for(int i=1; i<=row; i++)
{
for(int j=1; j<=row-i; j++)
{
cout<<" ";
}
for(int k =i ; k>=1; k--)
{
cout<<k<<" ";
}
for(int l =1 ; l<=i; l++)
{
if(l==1)
{
continue;
}
cout<<l<<" ";
}
cout<<endl;
}
}
.....................................another way ...........................................
#include<bits/stdc++.h>
using namespace std;
int main()
{
int row;
cout<<"row: ";
cin>>row;
for(int i=1; i<=row; i++)
{
int j;
for(j=1; j<=row-i; j++)
{
cout<<" ";
}
int k =i;
for(;j<=row;j++)
{
cout<<k--<<" ";
}
k=2;
for(;j<=row+i-1;j++)
{
cout<<k++<<" ";
}
cout<<endl;
}
}
---------------------------anothery way ---------------------------------
#include<bits/stdc++.h>
using namespace std;
int main()
{
int row,doub;
cout<<"row: ";
cin>>row; //4
for(int i= 1;i<=row;i++)
{
for(int j=1;j<=row-i;j++)
{
cout<<" ";
}
//int k;
for(int k=i;k>=1;k--)
{
cout<<k;
}
for(int k=2;k<=i;k++)
{
cout<<k;
}
for(int j=1;j<=row-i;j++)
{
cout<<" ";
}
cout<<endl;
}
}