C Program to Calculate Compound Interest

How to write a C Program to Calculate Compound Interest with an example. Compound interest is the interest calculated on the principal amount (original amount) plus the interest accumulated in the previous periods (years). In short, compound interest is interest on the original amount and interest on interest. Before we get into the example, let me show you the formula behind the calculation:

Future CI = Principal Amount * ( 1 + Rate of Interest) power Number of years

The above Code is called Future because it contains both the Principal Amount and Compound Interest. To calculate the CI, use the below formula:

CI = Future CI – Principal Amount

C Program to Calculate Compound Interest

This C program allows the user to enter the Principal Amount, Rate of Interest, and the number of years. By using those values, this Program finds Compound interest and FCI using the above-specified formula.

#include<stdio.h>
#include <math.h>
 
int main() 
{
   float PAmount, ROI, Time_Period, CIFuture, CI;
 
   printf("\nPlease enter the Principal Amount : \n");
   scanf("%f", &PAmount);
 
   printf("Please Enter Rate Of Interest : \n");
   scanf("%f", &ROI);
 
   printf("Please Enter the Time Period in Years : \n");
   scanf("%f", &Time_Period);
 
   CIFuture = PAmount * (pow(( 1 + ROI/100), Time_Period));
   CI = CIFuture - PAmount;
   
   printf("\nFuture Compound Interest for Principal Amount %.2f is = %.2f", PAmount, CIFuture);
   printf("\nCompound Interest for Principal Amount %.2f is = %.2f", PAmount, CI);
 
   return 0;
}
Program to Calculate Compound Interest

C program to calculate compound interest using functions

In the following example, we created a reusable function that accepts three double values and returns a double output. We can pass the principal (original) amount, rate of interest, and total number of years to a function. The user-defined function uses the math formula and the built-in C pow function to calculate the interest. From that value, we will return the compound interest.

#include<stdio.h>
#include<math.h>
double calcompoundInt(double p, double rate, double time) {
double amount = p * ((pow((1 + rate / 100), time)));
return amount - p;
}
int main(void)
{
double original = 500000;
double rate = 7.5;
double year = 5;

printf("Compound Interest = %.2f", calcompoundInt(original, rate, year));
}
Compound Interest = 217814.66

Also Read