What is the issue with my code?

ur code does not work when n == k please make changes [ update the boundary condition it is leading to run time error]
in case u are unable to do so fell free to ask