Please check the code i think my logic is right

code-https://ide.codingblocks.com/s/329752

Hey @amanb25
Did changes in your code and mentioned in comments: https://ide.codingblocks.com/s/329758