Skip to content

Commit ca30c9e

Browse files
authored
Merge pull request csubhasundar#171 from Teerthesh706/main
Diamond Pattern In CPP
2 parents cafbdb4 + f51f967 commit ca30c9e

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

c++/Dimond_pattern.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int n;
6+
cout << "Enter the number of rows (should be an odd number): ";
7+
cin >> n;
8+
9+
if (n % 2 == 0) {
10+
cout << "Please enter an odd number for a symmetric diamond pattern."<<endl;
11+
return 1;
12+
}
13+
14+
for (int i = 1; i <= n; i += 2) {
15+
for (int j = 0; j < (n - i) / 2; j++) {
16+
cout << " ";
17+
}
18+
for (int j = 0; j < i; j++) {
19+
cout << "*";
20+
}
21+
cout <<endl;
22+
}
23+
24+
for (int i = n - 2; i >= 1; i -= 2) {
25+
for (int j = 0; j < (n - i) / 2; j++) {
26+
cout << " ";
27+
}
28+
for (int j = 0; j < i; j++) {
29+
cout << "*";
30+
}
31+
cout <<endl;
32+
}
33+
34+
return 0;
35+
}

0 commit comments

Comments
 (0)