C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Compound Interest Calculation Program in C

Introduction

Compound Interest (CI) is the interest calculated not only on the initial principal but also on the accumulated interest of previous periods. It is commonly used in banking, investments, and loans.

The formula is:

A=P×(1+R/100) T   

 

CI = A − P

where

  • P = Principal (initial amount)
  • R = Rate of Interest (per annum, in %)
  • T = Time (in years)
  • A = Final Amount after time T

 

C Program: Compound Interest Calculation

C

#include <stdio.h>

#include <math.h>   // For pow() function

 

int main() {

    float principal, rate, time, amount, compound_interest;

 

    // Input principal, rate, and time

    printf("Enter Principal amount: ");

    scanf("%f", &principal);

 

    printf("Enter Rate of Interest (in %%): ");

    scanf("%f", &rate);

 

    printf("Enter Time (in years): ");

    scanf("%f", &time);

 

    // Calculate Amount using compound interest formula

    amount = principal * pow((1 + rate / 100), time);

 

    // Calculate Compound Interest

    compound_interest = amount - principal;

 

    // Display results

    printf("Final Amount = %.2f\n", amount);

    printf("Compound Interest = %.2f\n", compound_interest);

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter Principal amount: 1000
Enter Rate of Interest (in %): 10
Enter Time (in years): 2
Final Amount = 1210.00
Compound Interest = 210.00

OUTPUT 2 :
Enter Principal amount: 5000
Enter Rate of Interest (in %): 8
Enter Time (in years): 3
Final Amount = 6298.56
Compound Interest = 1298.56


Explanation

  1. User enters principal, rate, and time.
  2. Formula applied:
    • amount = P × (1 + R/100)^T
    • CI = amount - P
  3. The program uses the pow() function from <math.h> to calculate exponentiation.
  4. Output shows both Final Amount and Compound Interest.