存款利息计算
(谭浩强p15)
#include<stdio.h>
#include<math.h>
#define RATE_ONE 0.015
#define RATE_TWO 0.021
#define RATE_THREE 0.0275
#define RATE_FIVE 0.03
#define RATE_HUO 0.0035
double huoqi(double money,int n){
double sum=money*pow((1+RATE_HUO/4),4*n);
return sum;
}
double siqi(double money,int n){
double sum=money*(1+n*RATE_FIVE);
return sum;
}
double fenqi(double money,int n,int m){//m是先存n年期
double sum1;
double sum;
switch(m){
case 2:{
sum1=money*(1+m*RATE_TWO);
sum=sum1*(1+(n-m)*RATE_THREE);
}break;
case 3:{
sum1=money*(1+m*RATE_THREE);
sum=sum1*(1+(n-m)*RATE_TWO);
}break;
case 1:{
sum=money*pow((1+RATE_ONE),n);
}break;
}
return sum;
}
int main(){
printf("一次存五年:%lf\n",siqi(1000,5));
printf("先存两年期,后存三年期:%lf\n",fenqi(1000,5,2));
printf("先存三年期,再存两年期:%lf\n",fenqi(1000,5,3));
printf("存一年期,连存五次:%lf\n",fenqi(1000,5,1));
printf("活期存款:%lf\n",huoqi(1000,5));
}