logoStarPatterns
Back to Patterns

Sandglass Pattern

Pattern Result

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

Code Implementation

Explanation

The Sandglass Pattern creates a shape that resembles an hourglass or sandglass using asterisks. The pattern consists of three parts: the upper half (an inverted pyramid), the middle row (a single star), and the lower half (a regular pyramid). The algorithm ensures that n is odd to create a symmetrical sandglass. The upper half starts with a full row of stars and decreases in width with each subsequent row. The middle row contains a single star in the center. The lower half starts with a narrow row and increases in width with each subsequent row, ending with a full row of stars. The outer loops handle the three parts separately, while the inner loops handle the spaces and stars in each row.