Analyzing the given required pattern line-by-line:
The given shape resembles an arrow. It consists of n/2 spaces in each row except the special row (the middle row) where instead of those spaces, we print stars.
Focusing on the arrowhead, the stars first increase till middle row and then decrease. Increment and decrement take place by difference of 1.
We first program for the arrowhead construction:
This will yield us the arrowhead required:
Now we move forward to the tail of the arrow.
The condition is simple: instead of printing whitespaces in the middle row, we print the same number of stars as the number of spaces.
The modification in the code is made as follows; completing our code: