Reputation: 323
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))
Upvotes: 2
Views: 111
Reputation: 1983
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))
Upvotes: 5