Skip to content

Commit

Permalink
Day 5 (Pattern 1-8) - C, C++ & Python (#63)
Browse files Browse the repository at this point in the history
* Added C Pattern_1-8

* Added C++ Pattern_1-8

* Update README.md

* Add pattern 4-8 - Python

* Update README.md
  • Loading branch information
ashwek authored and Razdeep committed Dec 26, 2018
1 parent 55508d6 commit 5487f08
Show file tree
Hide file tree
Showing 22 changed files with 1,252 additions and 39 deletions.
23 changes: 23 additions & 0 deletions day5/C++/Pattern_1.cpp
@@ -0,0 +1,23 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<iostream>

using namespace std;

int main(){

int n;

cout<<"Enter n = ";
cin>>n;

for(int i=1; i <= n; i++){
for(int j=1; j<=i; j++)
cout<<j <<" ";
cout<<endl;
}
return 0;
}
23 changes: 23 additions & 0 deletions day5/C++/Pattern_2.cpp
@@ -0,0 +1,23 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<iostream>

using namespace std;

int main(){

int n, k=1;

cout<<"Enter n = ";
cin>>n;

for(int i=1; i <= n; i++){
for(int j=1; j<=i; j++)
cout<<k++ <<" ";
cout<<endl;
}
return 0;
}
30 changes: 30 additions & 0 deletions day5/C++/Pattern_3.cpp
@@ -0,0 +1,30 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<iostream>

using namespace std;

int main(){

int n;

cout<<"Enter n = ";
cin>>n;

//Upper-Half
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++)
cout<<j <<" ";
cout<<endl;
}
//Lower-Half
for(int i=n-1; i>=1; i--){
for(int j=1; j<=i; j++)
cout<<j <<" ";
cout<<endl;
}
return 0;
}
28 changes: 28 additions & 0 deletions day5/C++/Pattern_4.cpp
@@ -0,0 +1,28 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<iostream>

using namespace std;

int main(){

int n;

cout<<"Enter n = ";
cin>>n;

for(int i=1; i <=n; i++){
for(int s=i; s<n; s++) //Space
cout<<" ";

for(int j=0; j<i; j++) //Number-Sequence
cout<<(j+i) <<" ";
for(int j=i-2; j>=0; j--) //Reverse-Number-Sequence
cout<<(j+i) <<" ";
cout<<endl;
}
return 0;
}
25 changes: 25 additions & 0 deletions day5/C++/Pattern_5.cpp
@@ -0,0 +1,25 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<iostream>

using namespace std;

int main(){

int n;

cout<<"Enter n = ";
cin>>n;

for(int i=1; i <=n; i++){
for(int s=1; s<i; s++) //Space
cout<<" ";
for(int j=1; j<(n-i+1)*2; j++) //Triangle
cout<<"* ";
cout<<endl;
}
return 0;
}
34 changes: 34 additions & 0 deletions day5/C++/Pattern_6.cpp
@@ -0,0 +1,34 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<iostream>

using namespace std;

int main(){

int n;

cout<<"Enter n = ";
cin>>n;

//Upper-Half
for(int i=1; i <=n; i++){
for(int s=i; s<n; s++) //Space
cout<<" ";
for(int j=1; j<i*2; j++) //Triangle
cout<<"* ";
cout<<endl;
}
//Lower-Half
for(int i=2; i <=n; i++){
for(int s=1; s<i; s++) //Sapce
cout<<" ";
for(int j=1; j<(n-i+1)*2; j++) //Triangle
cout<<"* ";
cout<<endl;
}
return 0;
}
38 changes: 38 additions & 0 deletions day5/C++/Pattern_7.cpp
@@ -0,0 +1,38 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<iostream>

using namespace std;

int main(){

int n;

cout<<"Enter n = ";
cin>>n;

//Upper-Half
for(int i=1; i <=n; i++){
for(int j=i; j<=n; j++) //Left Triangle
cout<<"* ";
for(int s=1; s<i; s++) //Space
cout<<" ";
for(int j=i; j<=n; j++) //Right Triangle
cout<<"* ";
cout<<endl;
}
//Lower-Half
for(int i=1; i <=n; i++){
for(int j=1; j<=i; j++) //Left Triangle
cout<<"* ";
for(int s=1; s<=(n-i); s++) //Space
cout<<" ";
for(int j=1; j<=i; j++) //Right Triangle
cout<<"* ";
cout<<endl;
}
return 0;
}
38 changes: 38 additions & 0 deletions day5/C++/Pattern_8.cpp
@@ -0,0 +1,38 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<iostream>

using namespace std;

int main(){

int n;

cout<<"Enter n = ";
cin>>n;

//Upper-Half
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++) //Left Triangle
cout<<"* ";
for(int s=1; s<=(n-i); s++) //Space
cout<<" ";
for(int j=1; j<=i; j++) //Right Triangle
cout<<"* ";
cout<<endl;
}
//Lower-Half
for(int i=1; i<=n; i++){
for(int j=i; j<=n; j++) //Left Triangle
cout<<"* ";
for(int s=1; s<i; s++) //Space
cout<<" ";
for(int j=i; j<=n; j++) //Right Triangle
cout<<"* ";
cout<<endl;
}
return 0;
}
21 changes: 21 additions & 0 deletions day5/C/Pattern_1.c
@@ -0,0 +1,21 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<stdio.h>

void main(){

int n, i, j;

printf("Enter n = ");
scanf("%d", &n);

for(i=1; i <= n; i++){
for(j=1; j<=i; j++){
printf("%d ", j);
}
printf("\n");
}
}
21 changes: 21 additions & 0 deletions day5/C/Pattern_2.c
@@ -0,0 +1,21 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<stdio.h>

void main(){

int n, i, j, k=1;

printf("Enter n = ");
scanf("%d", &n);

for(i=1; i <= n; i++){
for(j=1; j<=i; j++){
printf("%d ", k++);
}
printf("\n");
}
}
27 changes: 27 additions & 0 deletions day5/C/Pattern_3.c
@@ -0,0 +1,27 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<stdio.h>

void main(){

int n, i, j;

printf("Enter n = ");
scanf("%d", &n);

//Upper-Half
for(i=1; i <=n; i++){
for(j=1; j<=i; j++)
printf("%d ", j);
printf("\n");
}
//Lower-Half
for(i=n-1; i>=1; i--){
for(j=1; j<=i; j++)
printf("%d ", j);
printf("\n");
}
}
25 changes: 25 additions & 0 deletions day5/C/Pattern_4.c
@@ -0,0 +1,25 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<stdio.h>

void main(){

int n, i, j, s;

printf("Enter n = ");
scanf("%d", &n);

for(i=1; i <=n; i++){
for(s=i; s<n; s++) //Space
printf(" ");

for(j=0; j<i; j++) //Number-Sequence
printf("%d ", (j+i));
for(j=i-2; j>=0; j--) //Reverse-Number-Sequence
printf("%d ", (j+i));
printf("\n");
}
}
22 changes: 22 additions & 0 deletions day5/C/Pattern_5.c
@@ -0,0 +1,22 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<stdio.h>

void main(){

int n, i, j, s;

printf("Enter n = ");
scanf("%d", &n);

for(i=1; i <=n; i++){
for(s=1; s<i; s++) //Space
printf(" ");
for(j=1; j<(n-i+1)*2; j++) //Triangle
printf("* ");
printf("\n");
}
}
31 changes: 31 additions & 0 deletions day5/C/Pattern_6.c
@@ -0,0 +1,31 @@
/**
* @author : ashwek
* @date : 26/12/2018
*/

#include<stdio.h>

void main(){

int n, i, j, s;

printf("Enter n = ");
scanf("%d", &n);

//Upper-Half
for(i=1; i <=n; i++){
for(s=i; s<n; s++) //Space
printf(" ");
for(j=1; j<i*2; j++) //Triangle
printf("* ");
printf("\n");
}
//Lower-Half
for(i=2; i <=n; i++){
for(s=1; s<i; s++) //Sapce
printf(" ");
for(j=1; j<(n-i+1)*2; j++) //Triangle
printf("* ");
printf("\n");
}
}

0 comments on commit 5487f08

Please sign in to comment.