i didnt get the condition of cst=2 to handle the last extra star in the last row
Handling the last row extra star
Hi @kashishsoni,
See when you are in the last row there is one extra star being printed by the last loop … So for case n=5 we print 5 stars when loop runs from cst=1 to cst<=5 … That means for cst =1 it prints one star then for cst =2 it prints one star and so on … Now extra star problem only arises when the row = n .So what if we run the last loop one less time whenever row = n . So we intitialize cst = 2 when row = n so that it prints one star for cst=2 and then for cst=3 and so on till cst = 5 … Now see the pattern that earlier the stars were being printed 5 times when cst was initialized as 1 but if we initialize it as 2 it will run one less time so we will get 4 stars now instead of 5.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.