Skip to content

Commit

Permalink
Merge pull request csubhasundar#171 from Teerthesh706/main
Browse files Browse the repository at this point in the history
Diamond Pattern In CPP
  • Loading branch information
sherigar authored Oct 16, 2023
2 parents cafbdb4 + f51f967 commit ca30c9e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions c++/Dimond_pattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
using namespace std;

int main() {
int n;
cout << "Enter the number of rows (should be an odd number): ";
cin >> n;

if (n % 2 == 0) {
cout << "Please enter an odd number for a symmetric diamond pattern."<<endl;
return 1;
}

for (int i = 1; i <= n; i += 2) {
for (int j = 0; j < (n - i) / 2; j++) {
cout << " ";
}
for (int j = 0; j < i; j++) {
cout << "*";
}
cout <<endl;
}

for (int i = n - 2; i >= 1; i -= 2) {
for (int j = 0; j < (n - i) / 2; j++) {
cout << " ";
}
for (int j = 0; j < i; j++) {
cout << "*";
}
cout <<endl;
}

return 0;
}

0 comments on commit ca30c9e

Please sign in to comment.