Program to find compound interest

21 Jun, 2022
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 – PWhere, P is principle amount R is the rate and T is the time span
Pseudo Code:  
Input principle amount. Store it in some variable say principle.
Input time in some variable say time.
Input rate in some variable say rate.
Calculate Amount using formula, 
Amount = principle * (1 + rate / 100)  time).
Calculate Compound Interest using Formula.
Finally, print the resultant value of CI.
Example:  
Input : Principle (amount): 1200
        Time: 2
        Rate: 5.4
Output : Compound Interest = 133.099243
 
C++
C
Java
Python3
C#
PHP
Javascript
// CPP program to find compound interest for// given values.#include <bits/stdc++.h>using namespace std; int main(){    double principle = 10000, rate = 5, time = 2;     /* Calculate compound interest */    double A = principle * (pow((1 + rate / 100), time));      double CI = A- principle;     cout << "Compound interest is " << CI;     return 0;}//This Code is Contributed by Sahil Rai.
// C program to calculate Compound Interest#include <stdio.h>#include<math.h> // for using pow function we must include math.h int main() {  double principal = 10000; // principal amount  double rate = 5; //annual rate of interest  double time = 2; // time   // Calculating compound Interest    double Amount = principal * (pow((1 + rate / 100), time));    double CI = Amount - principal;      printf("Compound Interest is : %lf",CI);    return 0;}
// Java program to find compound interest for// given values.import java.io.*; class GFG{    public static void main(String args[])    {        double principle = 10000, rate = 5, time = 2;         /* Calculate compound interest */        double A = principle *                    (Math.pow((1 + rate / 100), time));          double CI = A - principle;                 System.out.println("Compound Interest is "+ CI);    }} //This Code is Contributed by Sahil Rai.
# Python3 program to find compound# interest for given values. def compound_interest(principle, rate, time):     # Calculates compound interest    A = principle * (pow((1 + rate / 100), time))    CI= A - principle    print("Compound interest is", CI)  compound_interest(10000, 5, 2) #This Code is Contributed by Sahil Rai.
// C# program to find compound// interest for given valuesusing System; class GFG {     // Driver Code    public static void Main()    {        double principle = 10000, rate = 5, time = 2;         // Calculate compound interest        double A = principle * (Math.Pow((1 +                    rate / 100), time));          double CI = A - principle;                 Console.Write("Compound Interest is "+ CI);    }} //This Code is Contributed by Sahil Rai.
<?php// PHP program to find// compound interest for// given values. $principle = 10000;$rate = 5;$time = 2; // Calculate compound interest$A = $principle * (pow((1 +      $rate / 100), $time));$CI = $A - $principle; echo("Compound interest is " . $CI); ?>
<script> // JavaScript program to// find compound interest for// given values.     let principle = 10000, rate = 5,        time = 2;     /* Calculate compound interest */    let A = principle *        (Math.pow((1 + rate / 100), time));    let CI = A - principle;     document.write("Compound interest is " + CI);</script> // This Code is Contributed by Sahil Rai.
Output: 
Compound interest is 1025
Time complexity: O(log(m)) where m=1+rate/100
space complexity: O(1)
nitin mittal
jit_t
surbhityagi15
thesahilrai
akashish__
krishnav4
Mathematical
School Programming
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Count of subarrays with average K
Operators in C / C++
The Knight's tour problem | Backtracking-1
Count of longest possible subarrays with sum not divisible by K
Find minimum number of coins that make a given value
Python Dictionary
Reverse a string in Java
Arrays in C/C++
Interfaces in Java
Inheritance in C++