C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Total Payment and Total Interest Paid on a Loan Program in C

Introduction

When you take a loan, you repay it through EMIs (Equated Monthly Installments).

  • EMI Formula:

EMI = (P×R×(1+R)N) / ((1+R)N−1)

Where:

  • P = Principal Loan Amount
  • R = Monthly Interest Rate (Annual Rate ÷ 12 ÷ 100)
  • N = Loan Tenure in Months

From EMI, we can calculate:

  • Total Payment = EMI × N
  • Total Interest = Total Payment – Principal

 

C Program: Total Payment and Total Interest Paid on a Loan

C

#include <stdio.h>

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

 

int main() {

    float principal, rate, emi, totalPayment, totalInterest;

    int time, n;

    float monthlyRate;

 

    // Input loan details

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

    scanf("%f", &principal);

 

    printf("Enter annual rate of interest (in %%): ");

    scanf("%f", &rate);

 

    printf("Enter loan tenure (in years): ");

    scanf("%d", &time);

 

    // Convert values

    n = time * 12;                     // total months

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

 

    // EMI calculation

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

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

 

    // Total payment & interest

    totalPayment = emi * n;

    totalInterest = totalPayment - principal;

 

    // Display results

    printf("\nLoan Amount: %.2f", principal);

    printf("\nAnnual Interest Rate: %.2f%%", rate);

    printf("\nTenure: %d years (%d months)", time, n);

    printf("\nMonthly EMI: %.2f", emi);

    printf("\nTotal Payment (Principal + Interest): %.2f", totalPayment);

    printf("\nTotal Interest Paid: %.2f\n", totalInterest);

 

    return 0;

}

Output

 
OUTPUT :
Enter the loan amount (Principal): 500000
Enter annual rate of interest (in %): 10
Enter loan tenure (in years): 5

Loan Amount: 500000.00
Annual Interest Rate: 10.00%
Tenure: 5 years (60 months)
Monthly EMI: 10624.59
Total Payment (Principal + Interest): 637475.40
Total Interest Paid: 137475.40

Explanation

  1. User inputs principal, interest rate, and tenure.
  2. Program converts years → months and annual rate → monthly rate.
  3. EMI is calculated using the formula with pow() from <math.h>.
  4. Total Payment = EMI × number of months.
  5. Total Interest = Total Payment – Principal.