@Ishitagambhir, Corrected code, here.
@abhijeet.srivastava6499 i think you pasted the link for another code by accident
@Ishitagambhir, Sorry my bad, updated.
@abhijeet.srivastava6499 its giving incorrect output, please help
i figured it out, resolving the doubt