Skip to content

Commit 5487f08

Browse files
ashwekRazdeep
authored andcommitted
Day 5 (Pattern 1-8) - C, C++ & Python (#63)
* Added C Pattern_1-8 * Added C++ Pattern_1-8 * Update README.md * Add pattern 4-8 - Python * Update README.md
1 parent 55508d6 commit 5487f08

22 files changed

+1252
-39
lines changed

day5/C++/Pattern_1.cpp

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

day5/C++/Pattern_2.cpp

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

day5/C++/Pattern_3.cpp

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

day5/C++/Pattern_4.cpp

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

day5/C++/Pattern_5.cpp

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

day5/C++/Pattern_6.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @author : ashwek
3+
* @date : 26/12/2018
4+
*/
5+
6+
#include<iostream>
7+
8+
using namespace std;
9+
10+
int main(){
11+
12+
int n;
13+
14+
cout<<"Enter n = ";
15+
cin>>n;
16+
17+
//Upper-Half
18+
for(int i=1; i <=n; i++){
19+
for(int s=i; s<n; s++) //Space
20+
cout<<" ";
21+
for(int j=1; j<i*2; j++) //Triangle
22+
cout<<"* ";
23+
cout<<endl;
24+
}
25+
//Lower-Half
26+
for(int i=2; i <=n; i++){
27+
for(int s=1; s<i; s++) //Sapce
28+
cout<<" ";
29+
for(int j=1; j<(n-i+1)*2; j++) //Triangle
30+
cout<<"* ";
31+
cout<<endl;
32+
}
33+
return 0;
34+
}

day5/C++/Pattern_7.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @author : ashwek
3+
* @date : 26/12/2018
4+
*/
5+
6+
#include<iostream>
7+
8+
using namespace std;
9+
10+
int main(){
11+
12+
int n;
13+
14+
cout<<"Enter n = ";
15+
cin>>n;
16+
17+
//Upper-Half
18+
for(int i=1; i <=n; i++){
19+
for(int j=i; j<=n; j++) //Left Triangle
20+
cout<<"* ";
21+
for(int s=1; s<i; s++) //Space
22+
cout<<" ";
23+
for(int j=i; j<=n; j++) //Right Triangle
24+
cout<<"* ";
25+
cout<<endl;
26+
}
27+
//Lower-Half
28+
for(int i=1; i <=n; i++){
29+
for(int j=1; j<=i; j++) //Left Triangle
30+
cout<<"* ";
31+
for(int s=1; s<=(n-i); s++) //Space
32+
cout<<" ";
33+
for(int j=1; j<=i; j++) //Right Triangle
34+
cout<<"* ";
35+
cout<<endl;
36+
}
37+
return 0;
38+
}

day5/C++/Pattern_8.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @author : ashwek
3+
* @date : 26/12/2018
4+
*/
5+
6+
#include<iostream>
7+
8+
using namespace std;
9+
10+
int main(){
11+
12+
int n;
13+
14+
cout<<"Enter n = ";
15+
cin>>n;
16+
17+
//Upper-Half
18+
for(int i=1; i<=n; i++){
19+
for(int j=1; j<=i; j++) //Left Triangle
20+
cout<<"* ";
21+
for(int s=1; s<=(n-i); s++) //Space
22+
cout<<" ";
23+
for(int j=1; j<=i; j++) //Right Triangle
24+
cout<<"* ";
25+
cout<<endl;
26+
}
27+
//Lower-Half
28+
for(int i=1; i<=n; i++){
29+
for(int j=i; j<=n; j++) //Left Triangle
30+
cout<<"* ";
31+
for(int s=1; s<i; s++) //Space
32+
cout<<" ";
33+
for(int j=i; j<=n; j++) //Right Triangle
34+
cout<<"* ";
35+
cout<<endl;
36+
}
37+
return 0;
38+
}

day5/C/Pattern_1.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @author : ashwek
3+
* @date : 26/12/2018
4+
*/
5+
6+
#include<stdio.h>
7+
8+
void main(){
9+
10+
int n, i, j;
11+
12+
printf("Enter n = ");
13+
scanf("%d", &n);
14+
15+
for(i=1; i <= n; i++){
16+
for(j=1; j<=i; j++){
17+
printf("%d ", j);
18+
}
19+
printf("\n");
20+
}
21+
}

day5/C/Pattern_2.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @author : ashwek
3+
* @date : 26/12/2018
4+
*/
5+
6+
#include<stdio.h>
7+
8+
void main(){
9+
10+
int n, i, j, k=1;
11+
12+
printf("Enter n = ");
13+
scanf("%d", &n);
14+
15+
for(i=1; i <= n; i++){
16+
for(j=1; j<=i; j++){
17+
printf("%d ", k++);
18+
}
19+
printf("\n");
20+
}
21+
}

day5/C/Pattern_3.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @author : ashwek
3+
* @date : 26/12/2018
4+
*/
5+
6+
#include<stdio.h>
7+
8+
void main(){
9+
10+
int n, i, j;
11+
12+
printf("Enter n = ");
13+
scanf("%d", &n);
14+
15+
//Upper-Half
16+
for(i=1; i <=n; i++){
17+
for(j=1; j<=i; j++)
18+
printf("%d ", j);
19+
printf("\n");
20+
}
21+
//Lower-Half
22+
for(i=n-1; i>=1; i--){
23+
for(j=1; j<=i; j++)
24+
printf("%d ", j);
25+
printf("\n");
26+
}
27+
}

day5/C/Pattern_4.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @author : ashwek
3+
* @date : 26/12/2018
4+
*/
5+
6+
#include<stdio.h>
7+
8+
void main(){
9+
10+
int n, i, j, s;
11+
12+
printf("Enter n = ");
13+
scanf("%d", &n);
14+
15+
for(i=1; i <=n; i++){
16+
for(s=i; s<n; s++) //Space
17+
printf(" ");
18+
19+
for(j=0; j<i; j++) //Number-Sequence
20+
printf("%d ", (j+i));
21+
for(j=i-2; j>=0; j--) //Reverse-Number-Sequence
22+
printf("%d ", (j+i));
23+
printf("\n");
24+
}
25+
}

day5/C/Pattern_5.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @author : ashwek
3+
* @date : 26/12/2018
4+
*/
5+
6+
#include<stdio.h>
7+
8+
void main(){
9+
10+
int n, i, j, s;
11+
12+
printf("Enter n = ");
13+
scanf("%d", &n);
14+
15+
for(i=1; i <=n; i++){
16+
for(s=1; s<i; s++) //Space
17+
printf(" ");
18+
for(j=1; j<(n-i+1)*2; j++) //Triangle
19+
printf("* ");
20+
printf("\n");
21+
}
22+
}

day5/C/Pattern_6.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @author : ashwek
3+
* @date : 26/12/2018
4+
*/
5+
6+
#include<stdio.h>
7+
8+
void main(){
9+
10+
int n, i, j, s;
11+
12+
printf("Enter n = ");
13+
scanf("%d", &n);
14+
15+
//Upper-Half
16+
for(i=1; i <=n; i++){
17+
for(s=i; s<n; s++) //Space
18+
printf(" ");
19+
for(j=1; j<i*2; j++) //Triangle
20+
printf("* ");
21+
printf("\n");
22+
}
23+
//Lower-Half
24+
for(i=2; i <=n; i++){
25+
for(s=1; s<i; s++) //Sapce
26+
printf(" ");
27+
for(j=1; j<(n-i+1)*2; j++) //Triangle
28+
printf("* ");
29+
printf("\n");
30+
}
31+
}

0 commit comments

Comments
 (0)