#C4758. Diamond Pattern Printer
Diamond Pattern Printer
Diamond Pattern Printer
Given an integer n
, print a diamond shape composed of asterisks (*
). The diamond is constructed such that its widest row has n
asterisks, and every row is centered. Note that n
must be an odd number.
If n
is even, the program should output exactly: n must be an odd number
(without any additional characters or a newline at the end).
The diamond pattern for an odd number is defined as follows. Let \(m = \lfloor n/2 \rfloor\). For each row \(i\) from \(0\) to \(m\), print \(m-i\) spaces followed by \(2i+1\) asterisks. Then, for each row \(i\) from \(m-1\) down to \(0\), print \(m-i\) spaces followed by \(2i+1\) asterisks.
For example, if \(n=5\), the output (including newlines) should be:
* *** ***** *** *
inputFormat
The input consists of a single integer n
provided via standard input.
outputFormat
For an odd n
, output the diamond pattern on standard output, exactly matching the format. For an even n
, output the string n must be an odd number
with no trailing newline.
3
*
</p>