题目:
(1)一次存5年期
(2)先存2年期,到期后将本息再存3年期
(3)先存3年期,到期后将本息再存2年期
(4)存1年期,到期后将本息再存1年期,连续存5次
(5)存活期存款,活期利息每一季度结算一次
2017年银行存款利息如下:
- 1年期定期存款利息为1.5%;
- 2年期定期存款利息为2.1%;
- 3年期定期存款利息为2.75%;
- 5年期定期存款利息为3%;
- 活期存款利息为0.35%(活期存款每一季度结算一次利息)
如果r为年利率,n为存款年数,则计算本息的公式如下:
- 1年期本息和: P= 1000* (1+r);
- n年期本息和: P= 1000* (1+n* r);
- 存n次1年期的本息和: ;
- 活期存款本息和: P= 1000 *(1+);
说明: 1000*(1+)是一个季度的本息和。
分析:
本题在程序设计上没有难点,解题唯一的关键在于读懂题意。
代码实现:
#include <stdio.h>
#include <math.h>
int main()
{
const double money_start = 1000.0;
const double interest_1 = 0.015;//一次存1年利息
const double interest_2 = 0.021;//一次存2年利息
const double interest_3 = 0.0275;//一次存3年利息
const double interest_5 = 0.03;//一次存5年利息
const double interest = 0.0035;//活期利息,一个季度一结
double money_end = 0.0;
//一次存5年
money_end = money_start * (1 + 5 * interest_5);
printf("%lf\n", money_end);
//先存2年,到期后将本息再存3年
money_end = money_start * (1 + 2 * interest_2) * (1 + 3 * interest_3);
printf("%lf\n", money_end);
//先存3年,到期后将本息再存2年
money_end = money_start * (1 + 3 * interest_3) * (1 + 2 * interest_2);
printf("%lf\n", money_end);
//存一年期,到期后再将本息存一次,连续存5次
money_end = money_start * pow((1 + interest_1), 5);
printf("%lf\n", money_end);
//存活期,存5年
money_end = money_start * pow((1 + interest / 4), 4 * 5);
printf("%lf\n", money_end);
return 0;
}