Pages

Tuesday 8 December 2015

Compound Interest Calculation using C++



Compound Interest:


Compound interest is a interest that is added to the principal amount of the deposit or loan to gain interest on the accumulated  (principal + interest) amount.  The addition of interest to the principal amount is called as compounding.

Formula:


                    $A=P \times {(1+ \frac{r}{n})}^{nt}$
                    $ci = A - P $


Where:

  • $A =$ Accumulated Amount (principal + interest)
  • $P =$ Principal Amount
  • $I =$ Interest Amount
  • $R =$ Annual Nominal Interest Rate in percent
  • $r =$ Annual Nominal Interest Rate as a decimal
  • $r = R/100$
  • $t =$ Time Involved in years, 0.5 years is calculated as 6 months, etc.
  • $n =$ number of compounding periods per unit t; at the END of each period
  • $ci =$ Compound interst

Algorithm:

Steps:
  1. Input the principal amount, rate of interest and time (in years)
  2. Find the annual interest rate as decimal
  3. Compute the accumulated amount using the above formula
  4. Find the compound interest by subtracting the principal from accumulated amount. 
  5. Determine the compound interest
#include "iostream"
#include "conio.h"
#include "math.h"
using namespace std;

int main()
{
float p, r, n, ci;
int t;

    cout<<"Enter Principle amount :";
    cin >> p  ;
    cout << "Rate in %:" ;
    cin >> r  ;
    cout << "Time in years:" ;
    cin>> t;
    // Accumulated amount calculation 
    n = p*pow((1+r/100),t);
    // Compounded amount
    ci = n-p;

    cout << "\n" << "Compound Interest = " << ci << endl;
return (0);
}
INPUT:      Enter Principal Amount: 1200
                   Rate in % : 10
                   Time in years : 2
OUTPUT:  Compound interest : 252

No comments:

Post a Comment