sqrt -- Calculate Square Root

Format

#include <math.h>
double sqrt(double x);

Language Level: ANSI, POSIX, XPG4
sqrt calculates the nonnegative value of the square root of x.

Return Value
sqrt returns the square root result. If x is negative, the function sets errno to EDOM, and returns 0.

Example
This example computes the square root of the quantity passed as the first argument to main. It prints an error message if you pass a negative value.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char ** argv)
{
  char * rest;
  double value;
  if ( argc != 2 )
    printf( "Usage: %s value\n", argv[0] );
  else
  {
    value = strtod( argv[1], &rest );
    if ( value < 0.0 )
       perror( "sqrt of a negative number" );
    else
       printf("sqrt( %lf ) = %lf\n", value, sqrt( value ));
       return 0;
  }
  /**********************************************************
     The output should be:
     sqrt ( 45.000000 ) = 6.708204
  **********************************************************/
  }


exp -- Calculate Exponential Function
_fsqrt -- Calculate Square Root
hypot -- Calculate Hypotenuse
log -- Calculate Natural Logarithm
log10 -- Calculate Base 10 Logarithm
pow -- Compute Power
<math.h>