In: Computer Science
Write a program to calculate the amount of money in an account:
The user will input initial deposit and the number of years to leave that money in the account.
The interest is constant at 0.5% for the entire length of time.
The output will be the balance, with interest compounded annually.
(simple interest formula: interest = principal * rate)
Program:-
#include <stdio.h>
#include <math.h>
main(){
float p,r,a;
int n,t;
printf("Enter initial deposit: ");
scanf("%f",&p);
printf("Enter No of years: ");
scanf("%d",&t);
n = 1; //Since interest compounded annually
r = 0.005; // rate = 0.5/100
a = p * pow((1 + (r/n)),(n * t)); // FORMULA:- A =
P*((1 + r/n) ^ n*t)
printf("Money: %0.2f",a);
}
Variables Needed:-
p -> Initial deposit
r -> annual interest rate
n -> no of times interest compounded in an year
t -> time
a -> final amount
FORMULA:-
A = p * ((1 + n/t) ^ n*t)
OUTPUT:-
If you have any doubts , comment below. THANK YOU!!! Please rate the answer