I am having trouble with the syntax for computing distance formula using math and its sqrt function. Here is the equation. I tested it out and the answers are integers.
sqrt(double ((x1 - 0)^2) + double ((x2 - 0)^2))
I am having trouble with the syntax for computing distance formula using math and its sqrt function. Here is the equation. I tested it out and the answers are integers.
sqrt(double ((x1 - 0)^2) + double ((x2 - 0)^2))
In C/C++, ^ is the operator for bitwise exclusive-or (xor). I assume what you are looking for is way to raise a number to the power of 2. For this you can use the pow function from the C standard library:
pow(double n, double exp);
Specifically,
sqrt(double (pow(x1 - 0, 2)) + double (pow(x2 - 0, 2))