DAY12

 

 3.代码示例

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int i,x1,x2,x3,x5,x8,y1,y2,y3,y5,y8;
    double s=0,m=0.0;
    for(x8=0;x8<3;x8++){
        for(x5=0;x5<=(20-8*x8)/5;x5++){
            for(x3=0;x3<=(20-8*x8-5*x5)/3;x3++){
                for(x2=0;x2<=(20-8*x8-5*x5-3*x3)/2;x2++){
                    x1=20-8*x8-5*x5-3*x3-2*x2;
                    s=2000.0*pow((1+0.0063*12),x1)*pow((1+0.0066*12*2),x2)*pow((1+3*0.0069*12),x3)*pow((1+0.0075*12*5),x5)*pow((1+0.0084*12*8),x8);
                    //cout<<s<<endl;
                    if(s>m){
                        m=s;
                        y1=x1;y2=x2;y3=x3;y5=x5;y8=x8;
                    //    cout<<m<<endl;
                    } 
                }
            }
        }
    }
    cout<<"最佳存款方案为:"<<endl;
    cout<<y8<<"次八年期"<<endl<<y5<<"次五年期"<<endl<<y3<<"次三年期"<<endl<<y2<<"次两年期"<<endl<<y1<<"次一年期"<<endl;
    cout<<"最终本息共"<<m; 
    return 0;
} 

4。结果输出

 

posted @ 2023-04-25 23:15  奶油冰激凌  阅读(20)  评论(0)    收藏  举报