hello @mverma_be19 pls check ur updated code here->
Here’s your debugged code have added few comments for understanding.
@mr.encoder u shared the same debugged code .by removing his comment
oh i opened wrong doubt, i have to replied on some one else. Sorry for inconvenience @aman212yadav