Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 0 and 100;
Now please try your lucky.
Now please try your lucky.
2 100 -4
1.6152 No solution!
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
double l,h,mid,y;
double run(double x)
{
return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6;
}
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>y;
l=0;h=100;
while(l+1e-8<h)
{
mid=(l+h)/2;
if(run(mid)>y) h=mid;
else l=mid;
}
if (l==0||h==100) cout<<"No solution!"<<endl;
else printf("%.4lf\n",l);
}
return 0;
}
本文介绍了一种使用二分法求解特定多项式方程在0到100区间内的实数根的方法,并提供了完整的C++代码实现。该算法能够准确地找到方程的解或判断在指定范围内是否存在解。
252

被折叠的 条评论
为什么被折叠?



