4140:方程求解(二分查找)

4140:方程求解

总时间限制: 
1000ms
 
内存限制: 
65536kB
描述

求下面方程的根:f(x) = x3- 5x2+ 10x - 80 = 0。

输入
-
输出
精确到小数点后9位。
样例输入
-
样例输出
-

#include <bits/stdc++.h>
using namespace std;

double fun(double x){
	return  x*x*x-5*x*x+10*x-80;
}

int main(){
	double left=1,right=10;
	while(right-left>0.00000000001){
		double mid=left+(right-left)/2;
		if(fun(mid)>0){
			right=mid;
		}
		else left=mid;
	}
	printf("%.9lf\n",left);
	
	return 0;	
}

  



posted @ 2020-03-26 21:22  瓜瓜爱呱呱  阅读(381)  评论(0编辑  收藏  举报