p314159265
asked on
Math
How do I get the square root of a number?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you have any additional questions, please feel free to ask. Thanks!
ASKER
What does 'ASSERT' do?
"ASSERT" performs a test that, if failed, will stop the program's execution. In this case, it is basically saying, "If the square root of 4 is not 2, then stop the program from running." Obviously, you would want that to happen because the square root of 4 is obviously 2.
If you have further questions, please ask. Thanks!
If you have further questions, please ask. Thanks!
ASKER
Thanks, that about covers it.
Of course, you don't NEED to use ASSERT... Thresher just put it there as a code snippet to prove that the sqrt function works.
a=sqrt(b) is the only code you really need.
a=sqrt(b) is the only code you really need.
Yes, thank you scrapdog for clarifying :-)
I think you can use this function to get n root of a
Give a = x^n
=> x = exp((1/n)*log(a))
Give a = x^n
=> x = exp((1/n)*log(a))
#include <math.h>
.
double number = 4.0;
double result = sqrt (number);
ASSERT (result == 2.0);