用二分法求下面方程在(-10,10)的根:2x3-4x2+3x-6=0
程序员文章站
2024-02-02 15:20:40
...
用二分法求下面方程在(-10,10)的根:2x3-4x2+3x-6=0
#include <stdio.h>
#include <stdlib.h>
int f(int x)
{
return 2 * x*x*x - 4 * x*x + 3*x - 6;
}
int main()
{
int low = -10;
int high = 10;
int mid = (low + (high - low) / 2);
while (f(mid)!= 0)
{
if (f(mid)*f(low) < 0)
{
high = mid;
mid = (low + mid) / 2;
}
else
{
low = mid;
mid = (high + mid) / 2;
}
}
printf("%d", mid);
system("pause");
return 0;
}
答案
用二分法求下面方程在(-10,10)的根:2x3-4x2+3x-6=0
上一篇: 微机原理与接口技术实验:汇编综合练习
下一篇: fpga中求有符号数的绝对值