C++ Online Compiler
Example: Rhombus Pattern in C++ language of Stars using For loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// 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"; } }
8
Output
Clear
ADVERTISEMENTS