C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

EMI Comparison with Different Tenures and Rates Program in C

Introduction

A borrower often wants to know how EMI changes with:

  • Different loan tenures (e.g., 5 years vs. 10 years)
  • Different interest rates (e.g., 8% vs. 10%)

This program lets the user input a principal loan amount, then test different tenure and interest rate combinations.

 

C Program: EMI Comparison with Different Tenures and Rates

C

#include <stdio.h>

#include <math.h>   // for pow()

 

// Function to calculate EMI

float calculateEMI(float principal, float rate, int tenureYears) {

    int n = tenureYears * 12;                // months

    float monthlyRate = rate / (12 * 100);   // monthly rate

    float emi;

 

    emi = (principal * monthlyRate * pow(1 + monthlyRate, n)) /

          (pow(1 + monthlyRate, n) - 1);

 

    return emi;

}

 

int main() {

    float principal, rate;

    int tenure, i, j, nRates, nTenures;

 

    // Input principal amount

    printf("Enter loan amount (Principal): ");

    scanf("%f", &principal);

 

    // Input number of interest rates to test

    printf("Enter number of interest rates to compare: ");

    scanf("%d", &nRates);

 

    float rates[nRates];

    for (i = 0; i < nRates; i++) {

        printf("Enter annual interest rate %d (in %%): ", i + 1);

        scanf("%f", &rates[i]);

    }

 

    // Input number of tenures to test

    printf("Enter number of tenures to compare: ");

    scanf("%d", &nTenures);

 

    int tenures[nTenures];

    for (j = 0; j < nTenures; j++) {

        printf("Enter tenure %d (in years): ", j + 1);

        scanf("%d", &tenures[j]);

    }

 

    // Display EMI comparison table

    printf("\n=====================================================\n");

    printf("   Rate  |  Tenure (Years)  |   EMI (per month)\n");

    printf("=====================================================\n");

 

    for (i = 0; i < nRates; i++) {

        for (j = 0; j < nTenures; j++) {

            float emi = calculateEMI(principal, rates[i], tenures[j]);

            printf(" %6.2f%% | %10d       | %12.2f\n", rates[i], tenures[j], emi);

        }

    }

 

    printf("=====================================================\n");

 

    return 0;

}

Output

 
OUTPUT :
Enter loan amount (Principal): 500000
Enter number of interest rates to compare: 2
Enter annual interest rate 1 (in %): 8
Enter annual interest rate 2 (in %): 10
Enter number of tenures to compare: 2
Enter tenure 1 (in years): 5
Enter tenure 2 (in years): 10

=====================================================
   Rate  |  Tenure (Years)  |   EMI (per month)
=====================================================
   8.00% |          5       |     10138.07
   8.00% |         10       |      6066.37
  10.00% |          5       |     10624.59
  10.00% |         10       |      6607.55
=====================================================


Explanation

  1. User enters loan amount (Principal).
  2. User specifies how many interest rates and tenures they want to compare.
  3. Program stores them in arrays.
  4. The calculateEMI() function computes EMI for each (rate, tenure)
  5. A table is displayed with EMI values.