I'm having trouble converting the following formula:
Here's the image
The sqrt function will be used obviously, but how are squared numbers represented?
This is a discussion on having trouble converting the following formula within the C Programming forums, part of the General Programming Boards category; I'm having trouble converting the following formula: Here's the image The sqrt function will be used obviously, but how are ...
I'm having trouble converting the following formula:
Here's the image
The sqrt function will be used obviously, but how are squared numbers represented?
Last edited by Axel; 10-18-2005 at 02:43 AM.
The square of x is x * x.
It's in C++ but the formula is the same.
http://www.cprogramming.com/snippets...ount=30&page=0
Woop?
Here's my implementation (haven't looked at the C++ code, will do now)
the answer should be 3.11 but it's printing 2.36Code:double x1 = 4.40; double x2 = 3.30; double y2 = 7.70; double y1 = 8.80; printf("%l.2f", sqrt(x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
results of the C++ code(with the same values as above):
sqrt( ( pow( (x1 - x2), 2) + pow( (y1 - y2), 2) ) );
printf("%lf", sqrt( ( pow( (x1 - x2), 2) + pow( (y1 - y2), 2) ) ));
1.555635
hmm..
That is the correct answer. Check your calculations
x1 = 4.4
x2 = 3.3
y1 = 8.8
y2 = 7.7
x1 - x2 = 1.1
y1 - y2 = 1.1
1.1 ^ 2 = 1.21
1.21 + 1.21 = 2.42
sqrt(2.42) = 1.555....
Woop?
And your mistake in your first attempt were missing braces:
sqrt(x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)
should be:
sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) )