In this article, we are going to learn how to calculate Compound Interest using a C language program. The Compound Interest can be calculated by using a simple formula. The formula for Compound interest is:
Formula to calculate Compound Interest
Amount = Principal(1 + Rate/Num)^(NumTime)
Where:
- Amount: This is the amount value including interest and principal.
- Principal: This is the amount borrowed on interest.
- Rate: This is the rate in % at which interest will be charged
- Num: This number tells us how interest will be compounded. For example, Quarterly, Half Yearly, Annually.
- Time: This is the time for which this money is borrowed.
The Compound interest earned can be calculated with the below calculation once you have the Amount.
CompoundInterest = Amount - Principal;
- “Hello, World!” Program in C Language
- C Program to take input from users and print
- C Program to Add or Subtract two Integers
- C Program to Multiply and Divide Two Numbers
- C Program to Find Size of int, float,double, char, structure
- C Program to Find ASCII Value of Character
- C Program to Check Even or Odd Number
- C Program to Swap two numbers
- How to find square of Number in C languages
C Program to Calculate Compound Interest
Now let us see this formula in action using the C program below. We are asking the user to enter Principal, Interest, rate, and Time values and calculating the compound interest by using the above formula.
#include<stdio.h>
#include<math.h>
int main()
{
float PrincipalAmt, time, rate, num, Amount;
printf("Please enter the Principal Amount: ");
scanf("%f",&PrincipalAmt);
printf("Please enter the Rate of Interest: ");
scanf("%f",&rate);
printf("Please enter the Time: ");
scanf("%f",&time);
printf("Please enter the Number of Compounding: ");
scanf("%f",&num);
Amount = PrincipalAmt*pow( (1+(rate/num)), (num*time));
printf("The Amount will become : %.2f\n",Amount);
long CompoundInterest = Amount - PrincipalAmt;
printf("The Compound Interest Earned is : %.2f\n",CompoundInterest);
return 0;
}
Output