Skip to content

Commit f1e6313

Browse files
first commit
0 parents  commit f1e6313

File tree

10 files changed

+288
-0
lines changed

10 files changed

+288
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<h1 align="center"> C++ Patterns Code <img style="width: 50px" src="https://user-images.githubusercontent.com/72737691/161961213-56c74c51-8a63-4858-a33a-608f29f2fb24.png" /> </h1>
2+
<p align="center">
3+
Get all the pattern problem question code. Just do <b>git clone</b> and grow.
4+
</p>
5+
6+
## Contributors
7+
8+
- [Rishaw-Developer](https://github.com/Rishaw-Developer)
9+
10+
## Contributon
11+
Feel Free to add pattern code in this repo.
12+
- Only C++ code is accepted
13+
- Fork the repo
14+
- Create a branch
15+
- Make the changes
16+
- Create a pull request
17+
- In 1 or 2 days your code will be added
18+
- **And don't forgot to add your UserName in contributors section**

pattern1.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
/*
5+
Here row = 5 and col = 4
6+
* * * *
7+
* * * *
8+
* * * *
9+
* * * *
10+
* * * *
11+
*/
12+
13+
int main() {
14+
int row, col;
15+
16+
cin >> row >> col;
17+
18+
for (int i = 1; i <= row; i++) {
19+
for (int j = 1; j <= col; j++) {
20+
cout << '*' << ' ';
21+
}
22+
cout << endl;
23+
}
24+
return 0;
25+
}

pattern2.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
/*
5+
Here row = 5 and col = 4
6+
* * * *
7+
* *
8+
* *
9+
* *
10+
* * * *
11+
*/
12+
13+
int main()
14+
{
15+
int row, col;
16+
cin >> row >> col;
17+
18+
for (int i = 1; i <= row; i++)
19+
{
20+
for (int j = 1; j <= col; j++)
21+
{
22+
if (i == 1 || j == 1 || i == row || j == col)
23+
{
24+
cout << "* ";
25+
}
26+
else
27+
{
28+
cout << " ";
29+
}
30+
}
31+
cout << endl;
32+
}
33+
34+
return 0;
35+
}

pattern3.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
/*
5+
Here n = 5
6+
*
7+
* *
8+
* * *
9+
* * * *
10+
* * * * *
11+
*/
12+
13+
int main() {
14+
int n;
15+
cin >> n;
16+
17+
for (int i = 1; i <= n; i++) {
18+
for (int j = 1; j <= i; j++) {
19+
cout << "* ";
20+
}
21+
cout << endl;
22+
}
23+
}

pattern4.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
/*
5+
Here n = 5
6+
*
7+
* *
8+
* * *
9+
* * * *
10+
* * * * *
11+
*/
12+
13+
int main() {
14+
int n;
15+
cin >> n;
16+
17+
for (int i = 1; i <= n; i++) {
18+
for (int j = 1; j <= n-i; j++) {
19+
cout << " ";
20+
}
21+
for (int j = 1; j <= i; j++) {
22+
cout << "* ";
23+
}
24+
cout << endl;
25+
}
26+
}

pattern5.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
/*
5+
Here n = 5
6+
1
7+
1 2
8+
1 2 3
9+
1 2 3 4
10+
1 2 3 4 5
11+
*/
12+
13+
int main() {
14+
int n;
15+
cin >> n;
16+
int count;
17+
for (int i = 1; i <= n; i++) {
18+
for (int j = 1; j <= i; j++) {
19+
++count;
20+
cout << count << " ";
21+
}
22+
count = 0;
23+
cout << endl;
24+
}
25+
26+
return 0;
27+
}

pattern6.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
/*
5+
Here n = 5
6+
1
7+
2 3
8+
4 5 6
9+
7 8 9 10
10+
11 12 13 14
11+
*/
12+
13+
int main()
14+
{
15+
int n;
16+
cin >> n;
17+
18+
int count = 1;
19+
for (int i = 1; i <= n; i++){
20+
for (int j = 1; j <= i; j++){
21+
cout << count << " ";
22+
count++;
23+
}
24+
cout << endl;
25+
}
26+
}

pattern7.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
/*
6+
here n = 4
7+
* *
8+
* * * *
9+
* * * * * *
10+
* * * * * * * *
11+
* * * * * * * * * *
12+
* * * * * * * * * *
13+
* * * * * * * *
14+
* * * * * *
15+
* * * *
16+
* *
17+
*/
18+
19+
int main()
20+
{
21+
int n;
22+
cin >> n;
23+
24+
for (int i = 1; i <= n; i++)
25+
{
26+
for (int j = 1; j <= i; j++)
27+
{
28+
cout << "*" << " ";
29+
}
30+
for (int k = 1; k <= (2 * n - 2 * i); k++)
31+
{
32+
cout << " " << " ";
33+
}
34+
for (int j = 1; j <= i; j++)
35+
{
36+
cout << "*" << " ";
37+
}
38+
cout << endl;
39+
}
40+
for (int i = n; i >= 1; i--)
41+
{
42+
for (int j = 1; j <= i; j++)
43+
{
44+
cout << "*" << " ";
45+
}
46+
for (int k = 1; k <= (2 * n - 2 * i); k++)
47+
{
48+
cout << " " << " ";
49+
}
50+
for (int j = 1; j <= i; j++)
51+
{
52+
cout << "*" << " ";
53+
}
54+
cout << endl;
55+
}
56+
57+
return 0;
58+
}

pattern8.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
/*
5+
Here n = 5
6+
1 2 3 4 5
7+
1 2 3 4
8+
1 2 3
9+
1 2
10+
1
11+
*/
12+
13+
int main() {
14+
int n;
15+
cin >> n;
16+
17+
for (int i = 1; i <= n; i++){
18+
for (int j = 1; j <= n+1-i; j++) {
19+
cout << j << " ";
20+
}
21+
cout << endl;
22+
}
23+
24+
}

pattern9.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
/*
5+
Here n = 5
6+
1
7+
0 1
8+
1 0 1
9+
0 1 0 1
10+
1 0 1 0 1
11+
*/
12+
13+
int main() {
14+
int n;
15+
cin >> n;
16+
for (int i = 1; i <= n; i++) {
17+
for (int j = 1; j <= i; j++) {
18+
if ((i+j) % 2 == 0 ){
19+
cout << 1 << " ";
20+
} else {
21+
cout << 0 << " ";
22+
}
23+
}
24+
cout << endl;
25+
}
26+
}

0 commit comments

Comments
 (0)