Using for loop to calculate compound interest for 20 years
Using \" for \" loop to calculate compound interest for 20 years. The starting principal is 5000 and the rate is 0.04. Show amount on deposit for each year.
Solution
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
double principal=5000.0;
double rate=0.04;
int time=20;
double amt=principal;
for(int i=1;i<=20;i++)
{
printf(\"\ Deposit for year %d : %lf\",i,amt);
amt=amt+((amt*rate*1.0)/100);
}
printf(\"compound interest for 20 yrs : %lf\",(amt*pow(1.0+(rate/100),20)));
return 0;
}
