I want to convert Python to C++, but the answer is not correct. I'm trying to find the problem, but I couldn't. The code written for C++ works but does not give the correct answer.
import math
i=0
x=float(3)
while i==0:
h = float(((x**2)+1)/((math.log((x**2)+1))))
y = float(((((x**2)+1)**(1/h))))
s = float(((((x**2)+(4*x)+3)/((x**2)+1))))
print(" ---- ",x," ---- ",format(((s**100)-(y**100)), '.100f'))
x=(1.001)*x
if (s-y)<0:
i=1
print("the end")
/////////////////////////////////////
int i=0;
math::softfloat::float64_t x = 3.00;
while(i==0)
{
math::softfloat::float64_t h = ( math::softfloat::pow(x,2)+1)/
math::softfloat::log(math::softfloat::pow(x,2)+1);
math::softfloat::float64_t y1 = math::softfloat::pow(x,2)+1;
math::softfloat::float64_t y = math::softfloat::pow(y1,(1 / h));
math::softfloat::float64_t s = (math::softfloat::pow(x,2)+(4 * x)+3) /
(math::softfloat::pow(x,2)+1);
cout << "----" <<setprecision(15)<< x << "----" ;
cout << setprecision(4) << (math::softfloat::pow(s,100) -
math::softfloat::pow(y,100))<<endl;
x *= (1.001);
if(s - y < 0) i =1;
}
Aucun commentaire:
Enregistrer un commentaire