Skip to content

Commit

Permalink
Merge pull request #42 from alokrajpd/main
Browse files Browse the repository at this point in the history
diamond.cpp file modified
  • Loading branch information
ShaileshKumar007 committed Oct 12, 2022
2 parents 117968e + b10262d commit c6d6528
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion loops/diamond_pattern/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,67 @@
using namespace std;

void diamond_pattern(int n){
//Enter your code here
if (n % 2 == 0 || n <= 1)
cout << "-1" << endl;
else
{
int iF, lf, z = 0;
for (int i = 0; i < n / 2; i++) // first half
{
iF = 0;
lf = 0;
for (int j = 0; j < n; j++)
{
if (iF < n / 2 - i)
{
iF++;
cout << " ";
}
else if (lf < 2 * i + 1)
{
lf++;
cout << "*";
}
else
{
cout << " ";
}
}
for (int d = 0; d < i; d++)
{
cout << " ";
}
cout << endl;
}
for (int i = n / 2 + 1; i > 0; i--) // remaining
{
iF = n;
lf = n;
for (int j = n; j > 0; j--)
{
if (iF > n / 2 + i)
{
iF--;
cout << " ";
}
else if (lf > 2 * z)
{
lf--;
cout << "*";
}
else
{
cout << " ";
}
}
for (int d = i - 1; d > 0; d--)
{
cout << " ";
}
cout << endl;
z++;
}
}
}
int main()
{
Expand Down

0 comments on commit c6d6528

Please sign in to comment.