Skip to content

1. Square Star Pattern

Example

Pattern 1

\(N = 5\)

\[\Large
\begin{align}
* * * * *\\
* * * * *\\
* * * * *\\
* * * * *\\
* * * * *
\end{align}
\]
printSquare.cpp
#include <bits/stdc++.h>
using namespace std;

void printSquare(int n) {
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            cout << "* ";
        }
        cout << endl;
    }
}

int main(void) {
    int n;
    cin >> n;
    printSquare(n);
    return 0;
}

Input: 5
Output:

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *