I cannot understand the conditions when row=3 and col=5 and vice versa.please help me to solve this doubt
About the pattern
Complete program with extra added conditons
So basically in spiral print we either print and remove row or col one at a time
so
while(startcol<=endcol and startrow<=endrow)
is taking care of that ,that we have some row or column to remove
So for 3 rows and 5 cols
Assume rows are x,y,z and cols are a,b,c,d,e
So we first print x and remove it from available
then last coln i.e e
and so on
x->e->z->a->y we stop since all rows are finished that means that all elements are printed
So this is what internally implemented
Share the condition if u still arent able to understand any condition
I am unable to understand the if condition in both bottom row and start col
See as I told u that we print until we have a row & col left
So
We print first row last col
x -> e
Now before printing bottom row we need to check if rows are left or not hence we use startrow>=endrow
and then only we print
z
then we check if column is left or not so we check startcol>=endcol
and then we print
a
then in next iteration of loop we again check
then we print first row in this iteration i.e
y
and then we print last col i.e
d
but since no rows left so we are actually not prinitn anything here
next we check those conditions and since we are not left with rows or cols hence we don’t print
Thank you for a,b,c,d,e and X,y,z method now I am able to understand
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.