作业帮 > 综合 > 作业

求用割线法求方程x的3次方-2x-5=0在x0=2附近的根,取x0=2,x1-=2.2,计算到4位有效数字的C语言程序

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/16 14:03:33
求用割线法求方程x的3次方-2x-5=0在x0=2附近的根,取x0=2,x1-=2.2,计算到4位有效数字的C语言程序
#include
#include
float ff(float x)
{
return x*(x*x-2)-5;
}
float Secant(float x0,float x1)
{
return (x1 - (ff(x1)*(x1-x0))/(ff(x1)-ff(x0)));
}
void main()
{
int number,k=2;
float x0=2,x1=2.2,x2;
printf("x[0] = %.4f,x[1] = %.4f,",x0,x1);
while (1)
{
if (fabs(x0-x1)