Link to home
Start Free TrialLog in
Avatar of p314159265
p314159265

asked on

Math

How do I get the square root of a number?
ASKER CERTIFIED SOLUTION
Avatar of thresher_shark
thresher_shark

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thresher_shark
thresher_shark

To calculate the square root of a number, use the sqrt function like so:

#include <math.h>
.
double number = 4.0;
double result = sqrt (number);
ASSERT (result == 2.0);
If you have any additional questions, please feel free to ask.  Thanks!
Avatar of p314159265

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!
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.
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))