As you can see, you are printing too many columns inside a diamond. Therefore, the correction should be simple: print one column each time, what you do, reducing the number of cycles during which your cycle runs by one. Generally speaking, you can simply add - 1 to the end of the conditional expression, as @samgak suggests, but this does not actually work. Try to understand why you are faced with this problem.
Your first loop is independent of n ; it uses only the current line index to determine the number of characters to print. A.
In the second loop, you must also include n to start large and decrease the fill value, but you are using it incorrectly. n and row are the same value (since row is defined in terms of n ), but you only multiply row by 2 . Instead, you must first perform the n-row operation, and then scale the result by 2 to print 2 characters on each line. You will have to play a little with it, since 2*(n-row) not quite right, but I hope this is enough to help you sort out your problem.
source share