Star Printing - 7
Time limit1sMemory limit128 MB
Print a diamond shape of asterisks with a given height using spacing and counting rules.
- Level
Easy2 of 10
- Topics
- Implementation
- Solved
- No attempts yet
Problem
Given an integer N, print a diamond-shaped pattern of asterisks with height 2×N-1. The middle line contains 2×N-1 asterisks, and the lines above and below it are symmetric. Each line begins with the required number of spaces and has no trailing spaces after the asterisks.
Input
The first line contains an integer N. (1 ≤ N ≤ 100)
Output
Print 2×N-1 lines in total. For the i-th line of the top N lines (1 ≤ i ≤ N), print N-i spaces followed by 2×i-1 asterisks. Then print the lower N-1 lines by repeating the upper part in reverse order.