The required output format 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 RAM and console output:
Now we have to make certain adjustments to the present code, so that out output looks like the following:
Instead of printing the number of spaces and stars, now we write code to print the spaces and stars on console output.