How did we define int space

I understood the mechanism behind putting n-i spaces before the i’th line but why do we define it as a variable int space=1, shouldnt the initial condition be int space = n-1 as it is the first line

hello @crunchybanana
in that loop we are itereting n-i times only right?
space variable we are using is for counting purpose .
which we start from space= 1 and run till space<= n-i.

Aren’t we iterating n times (for n lines)

for each line we are iterating n-i times. where i is the line no

ok… and if the number of spaces are decreasing, why do we update it as space++? Shouldn’t it be space=space-1?

no .
in n-i , i is increasing right? that means n-i will be decreasing.
so evrytime we are printing less space when compared to previous line

1 Like

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.