Write a C Program to Calculate EMI using formula.
Equated Monthly Installments (EMIs) are monthly payments made by borrowers to creditors on a specific date. Over some years, the loan is repaid in full, with EMIs covering both interest and principal.
How to Calculate EMI with Example?
EMI calculator is used to calculate the per month EMI of the loan amount if loan amount that is principal, rate of interest and time in years is given as input.
The formula used to calculate EMI in this program is:
(P*R*(1+R)T)/(((1+R)T)-1)
Where,
P – Loan amount or principal amount
R – Interest Rate per month
T – Loan time Period in years
Example:
Given Principal = 20,000, Rate = 10 and Time in years = 2 yrs.
One Month Interest, r = r / (12 * 100)
r => 10 / (12 * 100) => 0.0084
Calculate EMI using (P*R*(1+R)T)/(((1+R)T)-1)
EMI = 922.899353
Start Step 1: Declare function to calculate EMI Function name->EMI(float principal, float rate, float time) float emi set r = rate / (12 * 100) Set t = time * 12 Set emi = (principal * rate * pow(1 + rate, time)) / (pow(1 + rate, time) - 1) Return emi Step 2: In main() Declare variables for principal amount, rate, time, emi Take input for principal amount , rate and time. Set EMI = calculate_EMI(principal, rate, time) Print EMI. Stop
Here is source code of the C program to calculate EMI. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Calculate EMI
*/
#include <math.h>
#include <stdio.h>
// Function to calculate EMI
float calc_emi(float p, float r, float t)
{
float emi;
// one month interest
r = r / (12 * 100);
// one month period
t = t * 12;
// Calculate EMI as per formula
emi = (p * r * pow(1 + r, t)) / (pow(1 + r, t) - 1);
return (emi);
}
// Driver Program
int main()
{
float principal, rate, t;
printf("Enter principal: ");
scanf("%f",&principal);
printf("Enter rate: ");
scanf("%f",&rate);
printf("Enter time in year: ");
scanf("%f",&t);
printf("\nMonthly EMI is= %f\n", calc_emi(principal, rate, t));
return 0;
}
1. Take input for principal amount, rate and time from the user.
2. Store these values in the variables principal, rate and t.
3. Call the function calc_emi to calculate EMI and pass the values as parameters.
4. Calculate one month interest using r = r / (12 * 100); and store it in the variable ‘r’.
5. Apply the formula (p * r * pow(1 + r, t)) / (pow(1 + r, t) – 1) to calculate EMI.
6. Return the calculated value of EMI.
7. Print the EMI value in main function.
Time Complexity: O(1)
We are using mathematical formula to calculate EMI, therefore programme computes result in constant time i.e. O(1).
Space Complexity: O(1)
Here we are using only three variables to store the values therefore the pogram uses constant space i.e. O(1).
In this case, we enter the principal amount as “20000,” the rate as “10,” and the time as “2” as input to calculate the EMI.
Enter principal: 20000 Enter rate: 10 Enter time in year: 2 Monthly EMI is= 922.899353
To practice programs on every topic in C, please visit “Programming Examples in C”, “Data Structures in C” and “Algorithms in C”.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Buy C Books
- Apply for C Internship
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Practice BCA MCQs