PROGRAMMING IN C. 1) The first program will compute compounded interest. Suppose
ID: 3671541 • Letter: P
Question
PROGRAMMING IN C. 1) The first program will compute compounded interest. Suppose you invest $1000.00 at an interest rate of 2% per year. If the interest is computed at the end of each day, it is added to your account (i.e., the interest is compounded daily). Print what the account value will be at the end of each year for 20 years. Use data type double for money. For 365 days per year (ignore leap year), the daily interest rate is 2%/ 365. Your program should request the following numbers as input from the user with scanf():
-Initial account balance (Start with $1000.00)
-Then run and demonstrate it again with the last 6 digits of your ID# so 876123456 would be: 1234.56)
-The annual interest rate in percent.
-Number of years: run it for at least 10 years.
For a compounding period of 1 (daily), the interest must be computed 365 times and accumulated. For a compounding period of 30 (monthly), the interest would be computed 365/30 or 12 times.Print the amount in the account including accumulated interest for each of 20 years for the following compounding periods if you started with $1,000 dollars: 1. Daily (period 1)
2. Weekly (7)
3. Monthly (30)
4. Quarterly (90)
5. Annually (365)
Use DOUBLE variables for your calculations. Run your program again for daily compounding using FLOAT variables, and note the difference in the results. Output should be formatted in columns, by year number something like this:
Year Daily Weekly Monthly Quarterly Annually
----- ------- ------- ------- --------- --------
0 1000.00 1000.00 1000.00 1000.00 1000.00
1 100x.xx 100x.xx 100x.xx 100x.xx 100x.xx
2 10xx.xx
Explanation / Answer
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23026 for x86
#include <stdio.h>
#include <math.h>
void main( )
{
double y[20];
double q[20];
double m[20];
double w[20];
double d[20];
/* p is principa,r is interest rate,t is time,the formula for compound interest
where "A" is the ending amount, "P" is the beginning amount (or "principal"), "r" is the interest rate (expressed as a decimal), "n" is the number of compoundings a year, and "t" is the total number of years.
Regarding the variables, n refers to the number of compoundings in any one year, not to the total number of compoundings over the life of the investment. If interest is compounded yearly, then n = 1; if semi-annually, then n = 2; quarterly, thenn = 4; monthly, then n = 12; weekly, then n = 52; daily, then n = 365;*/
double p, r;
int t;
p=1000;
r=2;
//calculating compound interest yearly and saved in y[]
for(t=0;t<20;t++)
{
y[t]=p*pow((3),t);
}
//calculating compound interest quartly and saved in q[]
for(t=0;t<20;t++)
{
q[t]=p*pow((1+r/4),(4*t));
}
//calculating compound interest in month and saved in m[]
for(t=0;t<20;t++)
{
m[t]=p*pow((1+r/12),(12*t));
}
//calculating compound interest week and saved in w[]
for(t=0;t<20;t++)
{
w[t]=p*pow((1+r/52),(52*t));
}
//calculating compound interest days and saved in d[]
for(t=0;t<20;t++)
{
d[t]=p*pow((1+r/365),(365*t));
}
printf("Year Daily Weekly Monthly Quarterly Annually " ) ;
for(t=0;t<5;t++)
{
printf("%d %.4f %.4f %.4f %.4f %.4f ",t,d[t],w[t],m[t],q[t],y[t]);
}
for(t=5;t<10;t++)
{
printf("%d %.4f %.4f %.4f %.4f %.4f ",t,d[t],w[t],m[t],q[t],y[t]);
}
for(t=10;t<15;t++)
{
printf("%d %.4f %.4f %.4f %.4f %.4f ",t,d[t],w[t],m[t],q[t],y[t]);
}
for(t=15;t<20;t++)
{
printf("%d %.4f %.4f %.4f %.4f %.4f ",t,d[t],w[t],m[t],q[t],y[t]);
}
}
Run program again replace the
double y[20];
double q[20];
double m[20];
double w[20];
double d[20]; to float arrays .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.