6

 源代码

#include <iostream>
#include <math.h>
using namespace std;
float fun(float a,float b,float c,float d){
float x0,x1=1.5,f,fd,h;
do{
f=x0*x0*x0+b*x0*x0+c*x0+d;
fd=3*a*x0*x0+2*b*x0+c;
h=f/fd;
x=x0-h;
}while(fabs(x-x0)>=1e-5);
return x;
}
int main(){
/*输入方程的系数/*
/*用牛顿迭代法求方程根*/
/*输出*/
float a,b,c,d;
cin>>a>>b>>c>>d;
float x=fun(a,b,c,d);
cout<<x;
}

posted @ 2023-04-18 16:49  晨观夕  阅读(6)  评论(0编辑  收藏  举报