#include<iostream>
using namespace std;
double fun(double x)
{
return 3*x*x*x-2*x*x+5*x-7;
}
double fun1(double x)
{
return 9 * x * x - 4 * x + 5;
}
int main()
{
double x0 = 1;
while (abs(fun(x0)) >=(10 ^ -6))
{
x0 = x0 - fun(x0) / fun1(x0);
}
cout<<x0<<endl;
system("pause");
return 0;
}
运行出的exe一直黑屏
死循环了。
添加头文件:#include <math.h>
while那修改一下:
while (abs(fun(x0)) >= pow(10.0,-6) )
{
x0 = x0 - fun(x0) / fun1(x0);
}
如有帮助,请采纳一下,谢谢。