To print a Rhombus Pattern in C++, we use nested loops. The outer loop controls the number of rows, and the inner loops control the spaces and stars (*) to form the pattern.
In this example,
n
to represent the desired number of rows in the rhombus.for
loops, where the outer loop runs from 1 to n
and the inner loops control the spaces and stars in each row.#include <iostream>
using namespace std;
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
cout << ' ';
}
for (int k = 1; k <= n; k++) {
cout << '*';
}
cout << '\n';
}
return 0;
}
***** ***** ***** ***** *****
In this tutorial, we learned How to print Rhombus Pattern in C++ language with well detailed examples.