C++ Code Example: hourglass pattern

This C++ program outputs a pattern in Hourglass shape on the screen. Two nested for loops are needed for this

#include <iostream>
using namespace std;

int main() {
    int i, j, k, n = 8;

    for (i = 1; i <= n; i++) {
        for (j = 1; j < i; j++) {
            cout << ' ';
        }

        for (k = i; k <= n; k++) {
            cout << "* ";
        }
        cout << endl;
    }
    for (i = n - 1; i >= 1; i--) {
        for (j = 1; j < i; j++) {
            cout << ' ';
        }
        for (k = i; k <= n; k++) {
            cout << "* ";
        }

        cout << endl;
    }

    return 0;
}
Output
* * * * * * * * 
 * * * * * * * 
  * * * * * * 
   * * * * * 
    * * * * 
     * * * 
      * * 
       * 
      * * 
     * * * 
    * * * * 
   * * * * * 
  * * * * * * 
 * * * * * * * 
* * * * * * * *