Do you mean how to calculate total repayable over time allowing for interest rates and repayments?
If so you need to google the word AMORTIZATION.
Once you see how it works, the answer will be obvious.
It is not a simple calculation, but it is easily followed and easily coded, I have done something similar in VB, so you should be able to do this in c#.
I found this
] and it should help you.