3.代码示例
#include<iostream> #include<cmath> using namespace std; int main(){ float a,b,c,d,x0,f,f1; cin>>a>>b>>c>>d; float x=2.0; while(fabs(x-x0)>=1e-5){ x0=x; f=a*x0*x0*x0+b*x0*x0+c*x0+d; f1=3*a*x0*x0+2*b*x0+c; x=x0-f/f1; } cout<<"所求方程的跟为:"<<x; return 0; }
4.结果输出
标签:f1,示例,Day6,float,x0,include From: https://www.cnblogs.com/cream867/p/17327331.html