Compound interest is the addition of interest to the principal (original) sum of a loan or deposit, or in
other words, interest on interest. It is the result of reinvesting interest, rather than paying it out, so that
interest in the next period is then earned on the principal sum plus previously-accumulated interest.
The compound interest is calculated using the formula below.
A = P(1 + (r/100))^n
Where:
A = total amount after n year
P = Principal or Original price
r = rate of interest per annum
N = number of years the money is invested
1 Write a program that will calculate the compound interest using the formula above with an annual interest
rate of 5.4 %.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
float P;
float A,n, r=5.4;
cout << "Enter the principal amount" << endl;
cin>>P;
cout<<"Enter the number of years"<<endl;
cin>>n;
A=P*pow((1+r/100),n)-P;
cout<<"Compound interest is : "<<A<<endl;
return 0;
}
Comments
Leave a comment