题目链接:http://noi.openjudge.cn/ch0111/02/
描述
有函数:
f(x) = x5 - 15 * x4+ 85 * x3- 225 * x2+ 274 * x - 121
已知 f(1.5) > 0 , f(2.4) < 0 且方程 f(x) = 0 在区间 [1.5,2.4] 有且只有一个根,请用二分法求出该根。
输入
无。
输出
该方程在区间[1.5,2.4]中的根。要求四舍五入到小数点后6位。
样例输入
无
样例输出
不提供
水题,ac:
/*1.849016*/
#include<stdio.h>
#include<string.h>
#include<math.h>
#define ll long long
#include<algorithm>
using namespace std;
double xin(double x)
{
double y;
y=x*x*x*x*x-15*x*x*x*x+85*x*x*x-225*x*x+274*x-121;
return y;
}
int main()
{
double l=1.5,r=2.40,x,y;
int can=x;
while(can*10%10==0)
{
x=(l+r)/2.0;
y=xin(x);
if(xin(x)<0)
r=x;
else if(xin(x)>0)
l=x;
else
{
printf("%0.6lf\n",x);
return 0;
}
can=x*10000000;
}
printf("%0.6lf\n",x);
return 0;
}