logoStarPatterns
Back to Patterns

Alphabet X Pattern

Pattern Result

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

Code Implementation

Explanation

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