#C9010. Diamond Pattern Generation
Diamond Pattern Generation
Diamond Pattern Generation
Your task is to generate a diamond-shaped pattern composed of asterisks (*
). Given an integer n, you are to print a diamond pattern with 2n - 1
rows. The diamond has a symmetric upper and lower part. The number of spaces and asterisks in each row follows the pattern:
For row i (0-indexed) in the top half (0 ≤ i < n):
- Number of leading and trailing spaces:
n - i - 1
- Number of asterisks:
2i + 1
The bottom half of the diamond is the reverse of the top half (excluding the middle row). For instance, when n = 3, the diamond is:
* *** ***** *** *
Ensure that your output exactly matches the expected pattern including spaces.
inputFormat
The input consists of a single integer n (1 ≤ n ≤ 100
), which represents the size of the diamond. Input is read from standard input.
outputFormat
Print the diamond pattern corresponding to the given integer n. There will be 2n - 1
lines printed to standard output. Each line should end with a newline character.
1
*
</p>