noiopenjudge02:二分法求函数的零点 二分

noiopenjudge02:二分法求函数的零点

练习二分练习练习二分~~~

#include 
#include 
#include 
#include 
#include 
using namespace std;

bool check(double mid)
{
    double f = pow(mid,5)-15.0*pow(mid,4)+85.0*pow(mid,3)-225.0*pow(mid,2)+274.0*mid-121.0;
    if(f > 0.0) return 1;
    return 0;
}

int main()
{
    double l = 1.5, r = 2.4, mid;
    while(r-l > 0.00000001)
    {
        mid = (l+r)/2.0;
        if(check(mid)) l = mid;
        else r = mid;
    }
    printf("%.6lf", mid);
    return 0;
}

你可能感兴趣的:(二分,水题,二分,零点)