解一元多次方程

题意:对于给出的函数8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,给定一个数Y,求x值。

思路:二分法。

感悟:做这样的简单题太爽了,既有满足感,又能提高信心,哈哈。

AC代码:

#include<iostream>
#include<iomanip>
using namespace std;
double f (double a)
{
    double s;
    s=8*a*a*a*a+7*a*a*a+2*a*a+3*a+6;
    return s;
}
int main()
{
    double t,a,l,h,m;
    cin>>t;
    for (int i=0;i<t;i++)
    {
        cin>>a;
        l=1;h=100;
        while (h-l>0.0000001)
        {
            m=(l+h)/2;
            if (f(m)>a)
            h=m;
            else
            l=m;
        }
            if (f(1)>a||f(100)<a)
        cout<<"No solution!"<<endl;
        else    cout<<fixed<<setprecision(4)<<m<<endl;
    }
    return 0;
}
        


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值