本关任务:编写一个程序,给出最佳存款方案。具体任务描述如下: 已知银行整存整取不同期限的年利率分别为
假设银行对定期存款过期部分不支付利息,现在某人有20000元,要存20年,问怎样存才能使20年后得到的本利之和最多?
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 int main() 5 { 6 int i8, i5, i3, i2, i1; 7 int n8, n5, n3, n2, n1; 8 double max = 0; 9 int n; 10 double capital,total; 11 scanf("%d,%lf",&n,&capital); 12 for(i8=0;i8<=n/8;i8++) 13 for(i5=0;i5<=n/5;i5++) 14 for(i3=0;i3<=n/3;i3++) 15 for(i2=0;i2<=n/2;i2++) 16 for(i1=0;i1<=n;i1++){ 17 if(i1+2*i2+3*i3+5*i5+8*i8==n){ 18 total=capital*pow(1.0225,i1)*pow(1+2*0.0243,i2)*pow(1+3*0.0270,i3)*pow(1+5*0.0288,i5)*pow(1+8*0.0300,i8); 19 if(total>max){ 20 max=total; 21 n1=i1; 22 n2=i2; 23 n3=i3; 24 n5=i5; 25 n8=i8; 26 } 27 28 } 29 } 30 printf("8 year: %d\n",n8); 31 printf("5 year: %d\n",n5); 32 printf("3 year: %d\n",n3); 33 printf("2 year: %d\n",n2); 34 printf("1 year: %d\n",n1); 35 printf("Total: %.2f\n",max); 36 return 0; 37 }