The sqrt() function in C++ returns the square root of a number. This function is defined in the cmath header file.
Mathematically, sqrt(x) = √x.
Example
sqrt() Syntax
The syntax of the sqrt() function is:
sqrt(double num);
sqrt() Parameters
The sqrt() function takes the following parameter:
- num - a non-negative number whose square root is to be computed
Note: If a negative argument is passed to sqrt(), domain error occurs.
sqrt() Return Value
The sqrt() function returns:
- the square root of the given argument
sqrt() Prototypes
The prototypes of sqrt() as defined in the cmath header file are are:
double sqrt(double x);
float sqrt(float x);
long double sqrt(long double x);
// for integral type
double sqrt(T x);
Example 1: C++ sqrt()
Output
Square root of 10.25 is 3.20156
Example 2: sqrt() function With integral Argument
Output
Square root of 464453422 is 21551.2