I had to find the result of a function f(x) = x / (1-x)^2
, where 0 < x < 1
.
The value had to be formatted up to 6
decimal places only.
Here is my C++ code:
float x; scanf("%f",&x);
printf("%.6f",x/((1-x)*(1-x)));
And I did for the same in Python:
x = float(input())
print ("%.6f" % (x/((1-x)**2)))
For some values of x, both the programs give different answers.
For example, for x = 0.84567
,
C++ gives 35.505867
and Python gives 35.505874
Why does this happen?
According to solution, the Python answers are right, while C++ answers are wrong.