Javascript program for calculating the compound interest
source link: https://www.geeksforgeeks.org/videos/javascript-program-for-calculating-the-compound-interest/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Javascript program for calculating the compound interest
- 70 Views
- 11/10/2022
In this video, we will write a javascript program to calculate compound interest.
What is compound interest?
Compound interest is the addition amount of interest in the principal sum.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 may be contrasted with simple interest, where interest is not added to the principal, so there is no compounding.
Formula: to calculate compound interest annually is given by:
Amount= P(1 + R/100)T
Compound Interest = Amount – P
Where,
P is the principal amount
R is the rate and
T is the time span
Now take some examples for calculating compound interest:
Example 1:
Input:
Principle (amount): 1200,
Time: 2,
Rate: 5.4
Output: Compound Interest = 133.099243
Example 2:
Input:
Principle (amount): 1000,
Time: 2
Rate: 5
Output: Compound Interest = 1025
Algorithm:
Step 1: Define principal amount, rate, and time.
Step 2: Apply the compound interest formula.
Step 2.1: Use math. pow() to calculate a number raised to the power of the same number.
Step 3: Print the Compound interest of the given input number.
Here the Time complexity and space complexity will be O(1).
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK