Skip to content

Commit

Permalink
pattern20
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijadhav03 authored Jun 1, 2024
1 parent 0a8e538 commit 20307cb
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions patterns/pattern20.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <bits/stdc++.h>
using namespace std;

void print_diamond(int n) {
int spaces = 2 * n - 2;

for (int i = 1; i <= 2 * n - 1; i++) {
int stars = (i <= n) ? i : 2 * n - i;

for (int j = 1; j <= spaces; j++) {
cout << " ";
}

for (int j = 1; j <= stars; j++) {
cout << "* ";
}

cout << endl;

spaces = (i < n) ? spaces - 2 : spaces + 2;
}
}

int main() {
int n;

cin >> n;

print_diamond(n);

return 0;
}

0 comments on commit 20307cb

Please sign in to comment.