logoStarPatterns
Back to Patterns

Plus Pattern

Pattern Result

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

Code Implementation

Explanation

The Plus Pattern creates a shape that resembles a plus sign (+) using asterisks. The pattern places stars only at positions where the row index equals the middle row index or where the column index equals the middle column index. All other positions contain spaces. The algorithm ensures that n is odd to create a symmetrical plus with a single star in the center. The outer loop iterates through each row, and the inner loop iterates through each column, placing stars only at the middle row and middle column positions.