logoStarPatterns
Back to Patterns

Diamond Pattern

Pattern Result

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

Code Implementation

Explanation

The Diamond Pattern combines two pyramid patterns to create a diamond shape. The first half is a regular pyramid, and the second half is an inverted pyramid. The algorithm first creates the upper half (including the middle row) by increasing the number of stars in each row. Then it creates the lower half by decreasing the number of stars, starting from the second-to-last row of the upper half.