C++ Online Compiler
Example: Diamond Pattern in C++ using For loop of Stars
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Diamond Pattern in C++ using For loop of Stars #include <iostream> using namespace std; int main() { int x, c, k, s = 1; cout << "-----Enter the number of rows-----\n"; cin >> x; s = x - 1; for (k = 1; k <= x; k++) { for (c = 1; c <= s; c++) cout << " "; s--; for (c = 1; c <= 2 * k - 1; c++) cout << "*"; cout << "\n"; } s = 1; for (k = 1; k <= x - 1; k++) { for (c = 1; c <= s; c++) cout << " "; s++; for (c = 1 ; c <= 2 * (x - k) - 1; c++) cout << "*"; cout << "\n"; } return 0; }
7
Output
Clear
ADVERTISEMENTS