Loan EMI with an adjusted last payment
A bank in Pune offers fixed instalment loans. Every month the customer pays the same instalment (EMI), except that rounding to cents leaves a few cents unpaid or overpaid, so the last payment is adjusted to close the balance exactly.
Use these rules, all with the decimal module and halves rounded up to 2 decimals: monthly rate r = annual / 1200. EMI = P*r*(1+r)^n / ((1+r)^n - 1) rounded to cents (when the rate is 0, EMI is P / n rounded to cents). Each month, interest = balance times r rounded to cents, and it is added to the balance before the payment. Months 1 to n-1 pay the EMI. In month n the payment is whatever balance plus interest remains.
Task: read three lines: principal, annual interest rate in percent, and number of months. Print three lines: EMI: x, Final payment: y and Total interest: z (the sum of the monthly interest amounts), each with 2 decimals.
Sample tests
Input
500000 9.5 36
Expected output
EMI: 16016.47 Final payment: 16016.65 Total interest: 76593.10
Input
75000 14.5 18
Expected output
EMI: 4661.23 Final payment: 4661.24 Total interest: 8902.15
Your answer is also checked against 4 hidden tests.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
