# square root function

• 05-15-2002
Unregistered
square root function
Im wondering how do I get the square root of a number in C. Can any body help. Thanx
• 05-15-2002
Prelude
>Im wondering how do I get the square root of a number in C.
The easiest way would be the sqrt() function in math.h.

-Prelude
• 05-16-2002
Lynux-Penguin
Example:
Code:

```#include <stdio.h> #include <math.h> int main() {         printf(sqrt(20));         return 0; }```
-Luke
• 05-16-2002
Salem
> printf(sqrt(20));
First parameter to printf is a string

printf( "%f\n", sqrt(20));
• 05-18-2002
stautze
You could also easily write your own by using Newton's method of successive approximations.
• 05-18-2002
Unregistered
or use a very simple ( time consuming ) method:

use a loop using long doubles and do a comparison of number * number to equal the desired number. a very basic approach. this will have some trouble with some numbers, though. didn't test it yet.

- toaster
• 05-18-2002
stautze
>use a loop using long doubles and do a comparison of number * number to equal the desired number. a very basic approach.

While your at it, you could reinvent the wheel.
• 05-18-2002
Unregistered
haha. no.
• 05-19-2002
Shiro
This is my favourite math reference:

http://mathworld.wolfram.com/SquareRootAlgorithms.html