C Programming/C Reference/math.h/sqrt

From Wikibooks, open books for an open world
Jump to: navigation, search

sqrt () is a C library function. It is mainly associated with programming language. It is considerd under [math.h] header file.

function:

     #include<cmath.h>
     double sqrt (double x );
     float sqrt (float x );
     long double sqrt (long double x );


Description: sqrt computes square root. And returns The square root of x. In C++, this function is overloaded in <complex> and <valarray> (see complex sqrt and valarray sqrt). If the argument is negative, a domain error occurs, setting the global variable errno to the value EDOM.


Return Value: Square root of x.

Portability: In C, only the double version of this function exists with this name.

Example:

 /* sqrt example */
 #include <stdio.h>
 #include <math.h>
 int main ()
 {
   double param, result;
   param = 1024.0;
   result = sqrt (param);
   printf ("sqrt(%lf) = %lf\n", param, result );
   return 0;
}


Output: sqrt(1024.000000) = 32.000000


See also: pow Raise to power (function).

log Compute natural logarithm (function).

exp compute exponent of number (function) .

All the above are Related functions of sqrt ().