每日打卡 第二周 1
6.牛顿迭代法求方程根
#include<bits/stdc++.h>
using namespace std;
double f(a,b,c,d){
double x0,x=1.5,f,fd;
do{
x0=x;
f=a*x0*x0*x0+b*x0*x0+c*x0+d;
fd=3*a*x0*x0+2*b*x0+c;
x=(x0-f)/fd;
}while(fabs(x-x0)>=1e-5);
return x;
}
int main(){
double c,d,a,b;
cin>>a>>b>>c>>d;
cout<<f(a,b,c,d)<<endl;
}
7.最佳存款方案
#include<bits/stdc++.h>
using namespace std;
int main(){
double b=0;
for(i=0;i<5;i++){
b=(b+1000)/(1+0.0063*12);
}
cout<<b<<endl;
}

浙公网安备 33010602011771号