-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from MercheLorenzo/main
Create any pattern you want (issue #1)
- Loading branch information
Showing
2 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//Code for DIAMOND star pattern | ||
//You can add or change the printDiamond(int n) in the main so the size of the diamond changes too. | ||
|
||
/* | ||
Output for 5 will be: | ||
* | ||
*** | ||
***** | ||
******* | ||
********* | ||
******* | ||
***** | ||
*** | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
// Prints diamond pattern with 2n rows | ||
void printDiamond(int n) | ||
{ | ||
int space = n - 1; | ||
|
||
// run loop (parent loop) | ||
// till number of rows | ||
for (int i = 0; i < n; i++) | ||
{ | ||
// loop for initially space, | ||
// before star printing | ||
for (int j = 0;j < space; j++) | ||
cout << " "; | ||
|
||
// Print i+1 stars | ||
for (int j = 0; j <= i; j++) | ||
cout << "* "; | ||
|
||
cout << endl; | ||
space--; | ||
} | ||
|
||
// Repeat again in reverse order | ||
space = 0; | ||
|
||
// run loop (parent loop) | ||
// till number of rows | ||
for (int i = n; i > 0; i--) | ||
{ | ||
// loop for initially space, | ||
// before star printing | ||
for (int j = 0; j < space; j++) | ||
cout << " "; | ||
|
||
// Print i stars | ||
for (int j = 0;j < i;j++) | ||
cout << "* "; | ||
|
||
cout << endl; | ||
space++; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
printDiamond(5); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//This is the code for a HEART star pattern | ||
|
||
/* | ||
Output will be like: | ||
***** ***** | ||
******* ******* | ||
********* ********* | ||
******************* | ||
***************** | ||
*************** | ||
************* | ||
*********** | ||
********* | ||
******* | ||
***** | ||
*** | ||
* | ||
The size of the heart will depend of n | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int i, j, n; | ||
|
||
printf("Enter value of n : "); //You can assign a value to n so the heart can have different sizes. | ||
scanf("%d", &n); | ||
|
||
//We go through everything and put * where necessary for our pattern | ||
for(i=n/2; i<=n; i+=2) | ||
{ | ||
for(j=1; j<n-i; j+=2) | ||
{ | ||
printf(" "); | ||
} | ||
|
||
for(j=1; j<=i; j++) | ||
{ | ||
printf("*"); | ||
} | ||
|
||
for(j=1; j<=n-i; j++) | ||
{ | ||
printf(" "); | ||
} | ||
|
||
for(j=1; j<=i; j++) | ||
{ | ||
printf("*"); | ||
} | ||
|
||
printf("\n"); | ||
} | ||
|
||
for(i=n; i>=1; i--) | ||
{ | ||
for(j=i; j<n; j++) | ||
{ | ||
printf(" "); | ||
} | ||
|
||
for(j=1; j<=(i*2)-1; j++) | ||
{ | ||
printf("*"); | ||
} | ||
|
||
printf("\n"); | ||
} | ||
|
||
return 0; | ||
} |