I am trying to solve this in c programming, maybe the logic that I provided is not working as expected.