I used for loop in c for this question but code is not running and i am not sure if the logic is okay or not