1.找到相关年份的限制条件(年总和不可以超过20);
2.根据限制遍历所有情况(采用循环);
3.定义Max记录最大值;
4.输出
#include<iostream>
using namespace std;
int x8,x5,x3,x2,x1;
double f(int num,double t,int m)
{
double sum=1;
for(int i=0;i<m;i++){
sum*=(1+num*t*12);
}
return sum;
}
int main(){
int times[5];
double t=0,Max;
for(x8=0;x8<=2;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++){
int x1= 20-8*x8-5*x5-3*x3-2*x2;
Max=f(8,0.0084,x8)*f(5,0.0075,x5)*f(3,0.0069,x3)*f(2,0.0066,x2)*f(1,0.0063,x1);
if(t>Max){Max=t;}
}
}
}
}
printf("最大的存款额是%.2f元",Max*2000);
return 0;
}
标签:12,int,Max,x8,x2,x3,存钱,day,x5 From: https://www.cnblogs.com/drz1145141919810/p/17341421.html