Introduction
Every home, car and education loan in India is repaid in Equated Monthly Instalments. This project implements the EMI formula and the amortisation schedule that banks print, which shows how each payment splits between interest and principal.
Problem statement
Objectives
- Translate a financial formula into C using pow()
- Simulate a process month by month with a loop
- Handle a zero-interest edge case
- Aggregate monthly values into yearly summaries
Features
- EMI, total payment and total interest
- Monthly schedule for loans up to 24 months
- Yearly summary for longer loans
- Zero-interest loans and last-month rounding handled correctly
Concepts demonstrated
- Floating-point arithmetic
- Loops
- Functions
- Edge cases
System architecture
emi implements P·r·(1+r)ⁿ / ((1+r)ⁿ − 1) with r = annual rate / 12 / 100, special-casing r = 0. schedule walks month by month: interest = balance × r, principal = EMI − interest, balance −= principal. In the last month the remaining balance is paid exactly, absorbing rounding. For long loans it sums twelve months before printing a row.
Folder structure
Complete source code
Makefile
What each file does
- src/main.c
emi(formula),schedule(amortisation loop with monthly/yearly modes) and input validation inmain.- Makefile
- Build automation:
makebuilds./app,make testruns the sample session and compares it with the expected output,make cleanremoves build files.
How to run it
Build
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
100000 10.5 6 m
Testing
- Compare with
tests/expected-output.txt: Rs 1,00,000 at 10.5% for 6 months gives an EMI of Rs 17,180.79. - Try
20 yat 8.5% for a yearly summary. - Try 0% interest: the EMI must be the amount divided by the months.
Common errors
undefined reference to `pow'
Add -lm to the gcc command on Linux.
EMI shows as inf or nan
The rate was 0 and the zero-interest branch was removed; dividing by (1+r)ⁿ − 1 = 0 gives infinity.
Possible improvements
- Show the effect of a prepayment on tenure and interest
- Export the schedule to CSV
- Compare two loan offers side by side
Additional challenges
- 1Given a desired EMI, compute the maximum loan amount.
- 2Compute the tenure needed to repay a loan with a fixed EMI.
- 3Add an annual step-up EMI option (EMI increases by x% each year).
Built and tested it yourself? Mark it to update your dashboard.