I think my logic is correct, but still not getting correct answer

I have applied the correct logic but still not getting the required answer, what change should i make to the code?

Hii, could anyone please help me with this, its been two days since I posted this. Thank You.

Hey @neetigya
initialize sum variable outside the function
because changes are not persist

correct code