logoStarPatterns
Back to Patterns

Alphabet K Pattern

Pattern Result

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

Code Implementation

Explanation

The K Pattern creates a shape that resembles the letter K using asterisks. The pattern consists of two parts: the upper part where the diagonal line moves from right to left, and the lower part where the diagonal line moves from left to right. In the upper part, each row starts with a star, followed by decreasing spaces, and ends with another star (except for the middle row). In the lower part, each row starts with a star, followed by increasing spaces, and ends with another star (except for the first row of the lower part). The algorithm uses nested loops to create the pattern: separate outer loops handle the upper and lower parts, while the inner loops handle the spaces in each row.