 |
example problems statement for:C Language |
someone invested $ 100 in a deposit account with an interest rate of 5%. It is assumed that all the flowers are combined with investment capital in the account, calculate and show the amount of money in the account at the end of each year for 10 years.
use the formula:
a = p (1 + r)²
P = the initial amount of capital invested
R = annual interest rate
n = number of years
a = the amount of money in the deposit at the end of year n
#include <stdio.h>
#include <math.h>
int main(void){
double a;
double P = 100;
double r = .05;
int year;
printf("%4s%21s\n","Year","Deposit");
for( year = 1 ;year <= 10; year++){
a = P * pow(1.0 + r, year);
printf("%4d%21.2f\n",year,a);
}
return 0;
}
double a;
double P = 100;
double r = .05;
"double" here has the same type with the "float". but the memory allocation "double" has a larger memory allocation from the "float".
printf("%4s%21s\n","Year","Deposit");
"% 4s and %21s" is used to issue a letter that has been called by printf "4s" means to display the "string" with a wide field of "4" to explain that the value to be displayed is at position "4" in the execution of the program.
a = P * pow(1.0 + r, year);
Pow (1.0 + r, year) This program is used to raise to "1.0 + r" with the number of years.
EXAMPLE
#include <stdio.h>
#include <math.h>
int main(void){
int a = 2;
int b = 3;
int raise;
raise = pow(a,b);
printf("%d",raise);
return 0;
}