每日打卡 第二周 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;

}

posted @ 2023-04-24 21:05  poemgranate  阅读(19)  评论(0)    收藏  举报