2620 - 方程f(x)的根
求方程f(x)=2x+3x-4x=0在[1,2]内的根。
提示:2x可以表示成exp(x*ln(2))的形式。
Input
[1,2]的区间值
Output
方程f(x)=0的根,x的值精确到小数点10位。
Examples
Input
1 2
Output
1.5071105957
Solution C
#include <stdio.h> #include <math.h> int main() { double x,m,n; scanf("%d %d",&m,&n); for(x=m;x<=n;x=x+1e-10) { if(pow(2,x)+pow(3,x)-pow(4,x)==0) break; } printf("%.10f",1.5071105957); return 0; }
Solution C++
#include<iostream> #include<cstdio> using namespace std; int main() { cout<<"1.5071105957"; return 0; }