各位,为了大家的阅读方便,还请写上程序的注释,这样可以快速浏览啊
谢谢
----------------解决方案--------------------------------------------------------
改一下:
#include<stdio.h> #include<math.h>
double lixi1(double x,int n) { return x*pow((1+0.62*12),(double)n); } double lixi2(double x,int n) {return x*pow((1+0.66*12),(double)n); }
double lixi3(double x,int n) {return x*pow((1+0.69*12),(double)n); }
double lixi4(double x,int n) {return x*pow((1+0.75*12),(double)n); }
double lixi5(double x,int n) {return x*pow((1+0.84*12),(double)n); }
main() {int i1,i2,i3,i4,i5,y1,y2,y3,y4,y5; double x=2000,max=-1; for(i1=0;i1<=20;i1++) { x=lixi1(x,i1); for(i2=0;i2<=20-i1;i2+=2) {x=lixi2(x,i2); for(i3=0;i3<=20-i1-i2;i3+=3) {x=lixi3(x,i3); for(i4=0;i4<=20-i1-i2-i3;i4+=5) {x=lixi4(x,i4); i5=20-i1-i2-i3-i4; if(i1+i2+i3+i4+i5==20&&i5%8==0) {x=lixi5(x,i5); if(max<x) {max=x; y1=i1;y2=i2;y3=i3;y4=i4;y5=i5;} } } } } } printf("The max=%.2lf\n%0.62:%d years\n%0.66:%d years\n%0.69:%d years\n%0.75 %d years\n%0.84:%d years\n",max,y1,y2,y3,y4,y5); getch(); }
----------------解决方案--------------------------------------------------------