65,210
社区成员
发帖
与我相关
我的任务
分享#include<iostream>
#include<cmath>
using namespace std;
const double p = 1000.00;
const double r = 0.05;
double cal(int n){
return p*pow(1 + r, n);
}
int main(){
for (int i = 0; i < 10; i++){
cout << i + 1 << '\t';
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
cout<< cal(i + 1) << endl;
}
}
Part Ⅱ:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
const double p = 24.00;
const double r[] = { 0.05, 0.06, 0.07, 0.08, 0.09, 0.10 };
double cal(int n,int j){
return pow(1 + r[j], n);
}
int main(){
int start_year = 1626;
double rate[6];
for (int i = 0; i < 6; i++)
rate[i] = cal(50, r[i]);
for (int k = 0; k < 6; k++){
cout << "年份\t利率"<<r[k] << endl;
for (int i = 1; i < 8; i++){
cout << start_year + i * 50 << '\t';
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
cout <<p*pow(rate[k], i) << '\t';
cout << endl;
}
cout << "2012\t";
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
cout << p*pow(rate[k], 7)*cal(36, k) << endl;
cout << endl;
}
}
最后的结果你再检查检查,仅供参考