C Program to Calculate Compound Interest

  • Write a C program to read principal amount, rate of interest and time and calculate compound interest.
  • Wap in C to find compound interest.

Required Knowledge

We will first read Principle amount, rate of interest and time using scanf function. We will use below mentioned formulae to calculate Compound Interest (CI).

  • Amount = P x (1 + R/100)T
  • Compound Interest = Amount – P

Where P, R and T are Principle, Rate of Interest and Time respectively.

C program to calculate compound interest

C program to calculate compound interest

/* 
 * C program to calculate compound interest 
 */ 
   
#include <stdio.h>  
#include <math.h>  
   
int main() {  
    float principle, rate, time, amount, interest; 
    /* 
     * Take principle, rate and time as input from user
     */ 
    printf("Enter Principle\n");  
    scanf("%f", &principle);
    printf("Enter Rate of Interest\n");  
    scanf("%f", &rate);  
    printf("Enter Time\n");  
    scanf("%f", &time);  
   
    /* Calculates Amount */ 
    amount = principle * pow((1 + rate/100), time);  
    /* Calculates Interest  */
    interest = amount - principle;
    printf("After %d Years\n", time);
    printf("Total Amount = %.4f\n", amount); 
    printf("Compound Interest Earned = %.4f", interest);  
   
    return 0;  
}

Output

Enter Principle
100000
Enter Rate of Interest
9
Enter Time
3
After 3 Years
Total Amount = 129502.9141
Compound Interest Earned = 29502.9141