sqrt()
Published Sep 8, 2022Updated Dec 21, 2022
Contribute to Docs
The sqrt()
function returns the square root of the argument.
Syntax
sqrt(x)
If the parameter x
is negative (less than 0), then a domain error will occur.
Example
The following example uses the sqrt()
function to find the square root of 4
:
#include <iostream>#include <cmath>int main() {double x = 4;double result;result = std::sqrt(x);std::cout << "The square root of " << x << " is " << result << "\n";// Output: The square root of 4 is 2}
Codebyte Example
The following example is runnable and returns the square root of 9
with the sqrt()
function:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.