|
-
January 12th, 2013, 11:58 AM
#5
Re: Trying to use C++ to solve a math problem
 Originally Posted by OmeshPH12
I had this riddle to solve and I know the answer to be
around ~ 12.31185723778668829963
Note that the precision of a double is only about 17 digits (including all digits before and after the decimal dot). Specifying more digits is superfluous.
Anyway what's that number above and how did you arrive at it?
Looking at the site you referred to you have these relations,
1/h = 1/A + 1/B
A^2 = b^2 - w^2
B^2 = a^2 - w^2
Solved for h you get this formula,
h = 1 / (1/sqrt(b^2 - w^2) + 1/sqrt(a^2 - w^2))
where a and b are the ladder lengths, h is the height above the alley floor up to where the ladders cross, and w is the alley width.
I suppose the number you posted is w, isn't it? When it's entered into the formula,
Code:
double a=40.0, b=30.0, w=12.311857237786688;
double h = 1.0 / (1.0/std::sqrt(b*b-w*w) + 1.0/std::sqrt(a*a-w*w));
std::cout << h << std::endl;
the result isn't 10 (as I guess it should be because c=10). So your solution doesn't seem correct.
Last edited by nuzzle; January 13th, 2013 at 02:28 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|