C Program to Calculate Monthly EMI

Howdy readers, today you will learn how to write a program to calculate monthly EMI using C Programming language.

C Program to Calculate Monthly EMI

When someone takes a loan from loan sharks, then the borrower has to pay a certain amount each month as an interest to the money lender. This certain amount is called the EMI or Equated Monthly Installment.

EMI is calculated using the following formula:

EMI = p * r * (1 + r)t  / ((1 + r)t – 1)

Where,

  • p = Principal Amount
  • r = Rate of Interest
  • t = Time period or No. of Installments

This program prompts the user to enter the principal amount, the annual rate of interest, and no. of installments, then it calculates the EMI amount using the above formula.

So, without any delay, let’s begin this tutorial.

C Program to Calculate Monthly EMI

C Program

// C Program to Calculate Monthly EMI
#include <stdio.h>
#include <math.h>

int main(){
    float principal, rate, time, emi;
    
    // Take input from the user
    printf("Enter the principal amount: ");
    scanf("%f", &principal);
    printf("Enter the rate of interest(annual): ");
    scanf("%f", &rate);
    printf("Enter the time period(in months): ");
    scanf("%f", &time);
    
    // Calculating interest rate per month 
    rate = rate / (12 * 100);
    
    // Calculating EMI
    emi = principal * rate * pow(1 + rate, time) / (pow(1 + rate, time) - 1);
    
    // Displaying result
    printf("Monthly EMI is: %.2f", emi);
    
    return 0;
}

Output

Enter the principal amount: 50000
Enter the rate of interest(annual): 3
Enter the time period(in months): 36
Monthly EMI is: 1454.03
C Program to Calculate Monthly EMI

Explanation

    float principal, rate, time, emi;

In the above program, we have declared four float data type variables named principal, rate, time, and emi.

    // Take input from the user
    printf("Enter the principal amount: ");
    scanf("%f", &principal);
    printf("Enter the rate of interest(annual): ");
    scanf("%f", &rate);
    printf("Enter the time period(in months): ");
    scanf("%f", &time);

The user is asked to enter the principal amount, the annual rate of interest, and no. of installments/Time period in months.

    // Calculating interest rate per month 
    rate = rate / (12 * 100);

Since, the interest rate is given in per annum, we will convert it into per month using the formula, Monthly Interest Rate = Rate / (12 * 100).

    // Calculating EMI
    emi = principal * rate * pow(1 + rate, time) / (pow(1 + rate, time) - 1);

Then, EMI is calculated using the formula, 

EMI = p * r * (1 + r) / ((1 + r)t – 1)

    // Displaying result
    printf("Monthly EMI is: %.2f", emi);

The EMI calculated in the previous step is displayed on the screen using printf() function. The %.2f format specifier is used to limit the result to 2 decimal places.

Conclusion

I hope after reading this tutorial, you understand how to write a program to calculate the monthly EMI using the C Programming language.

If you have any queries regarding the tutorial, then let us know in the comment section. We will be pleased to solve all of your queries.

Leave a Comment