My code is not working

Please help me in finding the problem in code.

hello @yashsharma4304

the issue is with this inner while loop.

image

pls dry run on some small case to find why it is stucked in infinite loop

What do you mean by this. Could you please explain me?

i mean follow ur code for some small input.

it is running for infinite no of times

Yes I know that the inner loop is running infinite times because firstly it will do col++ then col-- due to which the condition of loop never goes wrong and the loop will never terminate.
But what is the solution to this problem?

use one counter for inner loop . i.e while(counter<=2*row-1)
increment it whenever u print .

Now that problem is solved. But it is not printing the required output. Could you please help me with that?

break each row into three parts.
part a) print 1 to row numbers
part b) print spaces
part c) print row to 1 numbers

1 Like

Ok I will again make all conditions step by step. Thank you :slightly_smiling_face: