C Program to Calculate EMI

Problem Description

Write a C Program to Calculate EMI using formula.

What is EMI?

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.

advertisement
advertisement

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

Algorithm to calculate EMI
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
Program/Source Code

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.

Note: Join free Sanfoundry classes at Telegram or Youtube
  1. /*
  2.  * C Program to Calculate EMI
  3.  */
  4.  
  5. #include <math.h>
  6. #include <stdio.h>
  7.  
  8. // Function to calculate EMI
  9. float calc_emi(float p, float r, float t)
  10. {
  11.     float emi;
  12.     // one month interest
  13.     r = r / (12 * 100);
  14.     // one month period
  15.     t = t * 12;
  16.     // Calculate EMI as per formula
  17.     emi = (p * r * pow(1 + r, t)) / (pow(1 + r, t) - 1);
  18.     return (emi);
  19. }
  20. // Driver Program
  21. int main()
  22. {
  23.     float principal, rate, t;
  24.     printf("Enter principal: ");
  25.     scanf("%f",&principal);
  26.     printf("Enter rate: ");
  27.     scanf("%f",&rate);
  28.     printf("Enter time in year: ");
  29.     scanf("%f",&t);
  30.     printf("\nMonthly EMI is= %f\n", calc_emi(principal, rate, t));
  31.     return 0;
  32. }
Program Explanation

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).

advertisement

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).

Run Time Testcases

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”.

advertisement

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.