Find compound interest
Algorithm
Input P(Principal Amount),
r(Rate of Interest) ,
n(Number of times interest is calculated in a year) ,
t(number of years);
Output compound interest
Complexity O(1)
1 Compoundinterest(p, r , n , t)
2 A = P*(1+(r/n))^nt;
3 CI = A – p;
4 Return CI
Algorithm Description
Compound interest arises when interest is added to the principal, so that from that moment on, the interest that has been added also itself earns interest. This addition of interest to the principal is called compounding. It is calculated as per the formula given in the algorithm.
C Code
//Calculate Compound interest
//Input : p(Principal amount),r(interest rate),t(Time period in years),n(number of times interest is levied in a year)
#include< stdio.h>
#include< conio.h>
int main()
{
int p,r,t;
float final,ci;
printf("Enter principle amount ");
scanf("%d",&p);
printf("Enter interest rate ");
scanf("%d",&r);
printf("Enter time period(years) ");
scanf("%d",&t);
printf("Enter number of times the interest is levied in a year");
scanf("%d",&n);
final=(float)p(1+pow(r/(n*100)),(t*n));
ci=final-p;
printf("Amount with compound interest is %.2f",ci);
}