Skip to content

Commit

Permalink
Merge pull request #2 from MercheLorenzo/main
Browse files Browse the repository at this point in the history
Create any pattern you want (issue #1)
  • Loading branch information
pulkithanda committed Oct 23, 2021
2 parents 89b97a5 + de9a142 commit 47544cc
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
68 changes: 68 additions & 0 deletions diamond.cpp
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;
}
76 changes: 76 additions & 0 deletions heart.c
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;
}

0 comments on commit 47544cc

Please sign in to comment.