#include<bits/stdc++.h> using namespace std; int main(){ int x1, x2, x3, x5, x8, y1, y2, y3, y5, y8; double max = 0.0, result; 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 ++){ x1 = 20 - 8 * x8 - 5 * x5 - 3 * x3 - 2 * x2; result = 2000.0 * pow((1 + 0.0063 * 12), x1) * pow((1 + 2 * 0.0066 * 12), x2) * pow((1 + 3 * 0.0069 * 12), x3) * pow((1 + 5 * 0.0075 * 12), x5) * pow((1 + 8 * 0.0084 * 12), x8); if(result > max){ max = result; y1 = x1; y2 = x2; y3 = x3; y5 = x5; y8 = x8; } } } } } printf("获得利息最多的存款方式为: \n"); printf("8 年期限的存了%d次\n", y8); printf("5 年期限的存了%d次\n", y5); printf("3 年期限的存了%d次\n", y3); printf("2 年期限的存了%d次\n", y2); printf("1 年期限的存了%d次\n", y1); printf("存款人最终的获得的本息合计:%0.2f\n", result); }
标签:25,y8,x8,result,printf,y1,打卡,y3 From: https://www.cnblogs.com/kongxiangzeng/p/17353260.html