Only 1 testcase is passing in code 1, while getting tle in code 2. where am i wrong

QUES LINK: https://hack.codingblocks.com/contests/c/547/1251

CODE 1 LINK: https://ide.codingblocks.com/s/43523
CODE 2 LINK: 43524

https://ide.codingblocks.com/s/43534

Just a small mistake on line 17. I have corrected and commented it.