forked from csubhasundar/CodingPractice-Hacktoberfest23
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request csubhasundar#171 from Teerthesh706/main
Diamond Pattern In CPP
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |