Compound interest is the interest calculated on the principal amount as well as the interest accumulated during previous periods. It is commonly used for loans, investments, and savings where interest is compounded over time.
- Compound interest allows previously earned interest to contribute to future interest.
- The total amount is calculated first, and the original principal is then subtracted to obtain the compound interest.
Illustration
Input: P = 1200, R = 5.4, T = 2
Output: Compound Interest = 133.0992Input: P = 10000, R = 5, T = 2
Output: Compound Interest = 1025
Formula
For annual compounding, the total amount is calculated as:
A = P\left(1+\frac{R}{100}\right)^T
The compound interest is:
CI = A-P
Where:
- P is the principal amount.
- R is the annual rate of interest.
- T is the time period in years.
- A is the total amount after compounding.
Approach
- Initialize the principal amount, rate of interest, and time period.
- Calculate the total amount using the compound interest formula.
- Subtract the principal amount from the total amount.
- Print the calculated compound interest.
Example: Program to find Compound Interest.
#include <bits/stdc++.h>
using namespace std;
// Driver code
int main()
{
double principal = 10000, rate = 5, time = 2;
// Calculate compound interest
double A = principal * ((pow((1 + rate / 100), time)));
double CI = A - principal;
cout << "Compound interest is " << CI;
return 0;
}
Output
Compound interest is 1025
Explanation: In this example, the principal amount, rate of interest, and time period are initialized using double variables. The total amount is calculated using std::pow(), and the principal amount is subtracted from it to obtain the compound interest.