The required output format line by line can be represented as:
For achieving the desired result, we take help of a familiar code:
We declare sp for spaces (tabs) required and st for stars required on a particular line.
For an input value of n =5, the program will yield the following output: Now analyzing this output, we can see that it gives numbers resembling the above illustration which shows us what we required in each line, in terms of spacing and star printing.
We draw a memory diagram to showcase the relation between the RAM and console output:
Which corresponds with the values for number of stars, followed by number of spaces;ultimately again followed by number of stars required on a line.
Now that we have understood the spacing and star printing conceptually, we modify this code to get out final submission ready code.
Now, we have to make certain adjustments to our code to make our output look like this:
Instead of printing the number of spaces, we print the spaces and number of stars, the stars are printed.