Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C++
Run-Time Library
 sqrt, sqrtf
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Run-Time Library Reference
sqrt, sqrtf

Calculates the square root.

double sqrt(
   double x 
);
float sqrt(
   float x 
);  // C++ only
long double sqrt(
   long double x
);  // C++ only
float sqrtf(
   float x 
);
x

Nonnegative floating-point value

C++ allows overloading, so users can call overloads of sqrt that take float or long double types. In a C program, sqrt always takes and returns double.

The sqrt function returns the square-root of x. If x is negative, sqrt returns an indefinite, by default.

Input

SEH Exception

Matherr Exception

± QNAN,IND

none

_DOMAIN

- ∞

INVALID

_DOMAIN

x>0

INVALID

_DOMAIN

Routine

Required header

sqrt, sqrtf

<math.h>

For additional compatibility information, see Compatibility in the Introduction.

// crt_sqrt.c
// This program calculates a square root.

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

int 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 );
}
The square root of 45.35 is 6.73
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker