Chapter Contents

Previous

Next
sqrt

sqrt



Compute the Square Root

Portability: ISO/ANSI C conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
DIAGNOSTICS
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <math.h>

double sqrt(double x);


DESCRIPTION

sqrt computes the square root of its argument x .


RETURN VALUE

sqrt returns the positive square root of x , expressed as a double-precision, floating-point number.


DIAGNOSTICS

For a negative value of x , the function returns 0.0, and the run-time library writes an error message to stderr (the standard error file).

If an error occurs in sqrt , the _matherr routine is called. You can supply your own version of _matherr to suppress the diagnostic message or modify the value returned.


EXAMPLE

#include <math.h>
#include <stdio.h>

main()
{
   double x;
   puts("Enter the number you want the square root of: ");
   scanf("%lf", &x);
   printf("The square root of %f is %f\n", x, sqrt(x));
}


RELATED FUNCTIONS

hypot , _matherr


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.