The Program C++ to Display the pattern like Diamond is given below:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Hello Codeauri Family,enter the number of rows to display the patter (Diamond): \n";
cin >>n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
cout << " ";
}
for (int j = 1; j <= 2 * i - 1; j++) {
cout << "*";
}
cout << endl;
}
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= n - i; j++) {
cout << " ";
}
for (int j = 1; j <= 2 * i - 1; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}
Output:
Hello Codeauri Family,enter the number of rows to display the pattern (Diamond):
10
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*
Pro-Tips💡
This program will display a diamond pattern with a number of rows specified by the user.
The outer for loop is used to iterate through the rows, and the inner for loops are used to print the appropriate number of spaces and asterisks for each row.
The program first prints the upper half of the diamond, and then the lower half.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.