Here is the problem result Image
There result is 3024 but right result will be 3025; what is the problem please help ! thanks for advance.
Here is the problem result Image
There result is 3024 but right result will be 3025; what is the problem please help ! thanks for advance.
Because pow
is a floating point function that does its job using logarithms. It converted your 55 to floating point, then did the pow
function using logarithms. The result was probably 3024.999999, but when you converted back to an integer, it got truncated.
If you want to square an integer, use result = result * result;
. If you must use pow
for integer numbers, do
result = pow(result,2)+0.5;
I tried your code (ubuntu), the result is 3025. According to another answers, the problem is about the purpouse of pow implementation, with small calculations can be inaccurate, so, try with
result = result*result