Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript program to find compound interest

Improve Article
Save Article
  • Last Updated : 02 Dec, 2022
Improve Article
Save Article

What is ‘Compound interest’ ? 
Compound interest is the addition of interest to the principal 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. Compound interest is standard in finance and economics.
Compound interest may be contrasted with simple interest, where interest is not added to the principal, so there is no compounding.

Compound Interest formula: Formula to calculate compound interest annually is given by:

Amount= P(1 + R/100)t
Compound Interest = Amount - P

P is the principal amount 
R is the rate and 
T is the time span

Pseudo Code: 

Input principal amount. Store it in some variable say principal.
Input time in some variable say time.
Input rate in some variable say rate.
Calculate Amount using the formula, 
Amount = principal * (1 + rate / 100)  time).
Calculate Compound Interest using Formula.
Finally, print the resultant value of CI.


Input: Principal (amount): 1200, Time: 2, Rate: 5.4
Output: Compound Interest = 133.099243

Implementation: Below is the implementation of above approach:


    let principal = 10000, rate = 5,
        time = 2;
    /* Calculate compound interest */
    let A = principal *
        (Math.pow((1 + rate / 100), time));
    let CI = A - principal;
    console.log("Compound interest is " + CI);


Compound interest is 1025

Time Complexity: O(1), as there is no loop used so constant time.
Auxiliary Space: O(1).

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!