sqrt
Calculates the square root.
doublesqrt(doublex**);**
Routine | Required Header | Compatibility |
sqrt | <math.h> | ANSI, Win 95, Win NT |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB | Single thread static library, retail version |
LIBCMT.LIB | Multithread static library, retail version |
MSVCRT.LIB | Import library for MSVCRT.DLL, retail version |
Return Value
The sqrt function returns the square-root of x. If x is negative, sqrt returns an indefinite (same as a quiet NaN). You can modify error handling with _matherr.
Parameter
x
Nonnegative floating-point value
Example
/* SQRT.C: This program calculates a square root. */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
double question = 45.35, answer;
answer = sqrt( question );
if( question < 0 )
printf( "Error: sqrt returns %.2f\n, answer" );
else
printf( "The square root of %.2f is %.2f\n", question, answer );
}
Output
The square root of 45.35 is 6.73