Rhombus Pattern in C++ language of Stars using For loop
ADVERTISEMENTS
Rhombus pattern in c++ language of stars using for loop. In this article, you will learn how to print the rhombus pattern in c++ language of stars using for loop.
Source Code
// Rhombus Pattern in C++ language of Stars using For loop
#include <iostream>
using namespace std;
int rhombusPattern(int x);
int main() {
int x;
// x - denotes the number of rows
cout << "-----Enter the total number of rows-----\n";
cin >> x;
if (x > 0) {
// calling function to print the pattern
rhombusPattern(x);
}
return 0;
}
int rhombusPattern(int x) {
int i, j;
for (i = 1; i <= x; i++) {
// print the spaces
for (j = i; j < x; j++)
cout << " ";
// print the stars
for (j = 1; j <= x; j++)
cout << "*";
cout << "\n";
}
}
Output
-----Enter the total number of rows-----
8
********
********
********
********
********
********
********
********