#K43832. Generate Diamond Pattern
Generate Diamond Pattern
Generate Diamond Pattern
Given an odd integer n, output a symmetric diamond pattern composed of star characters (*
). The pattern has exactly n
characters in its widest row and is centered horizontally.
For example, when n is 5, the expected output is:
* *** ***** *** *
The number of stars in the i-th line from the top (starting from 0) in the upper half (including the middle) follows the formula: \(2i+1\) for \(0 \le i \le m\), where \(m = \lfloor n/2 \rfloor\). The lower half is a mirror image of the upper half (excluding the middle row).
inputFormat
The input is a single odd integer n
provided via stdin.
outputFormat
Print the diamond pattern, with each of its rows printed on a new line to stdout. Each row must have exactly n
characters, including spaces.
1
*
</p>