C++ cmath sqrt() function
Example
Return the square root of different numbers:
cout << sqrt(0);
cout << sqrt(1);
cout << sqrt(9);
cout << sqrt(0.64);
cout << sqrt(-25);
Try it Yourself »
Definition and Usage
The sqrt()
function returns the square root of a number.
The sqrt()
function is defined in the <cmath>
header file.
Syntax
One of the following:
sqrt(double number);
sqrt(float number);
Parameter Values
Parameter | Description |
---|---|
number | Required. Specifies a number. If the number is an integer type then it will be treated as a double . |
Technical Details
Returns: | A float value (if the argument is float) or double value (in any other case) representing the square root of a number. |
---|