Home > Article > Backend Development > How to use root sign in c++
Use the sqrt() function in C to find the square root. The syntax is: double y = sqrt(x); where x is a non-negative number and y is the calculated square root value. Example: Find the square root of 16: #include
, double number = 16, double squareRoot = sqrt(number), cout << "The square root is:" << squareRoot << endl; .
How to use the root sign in C
In C, you can use sqrt()
Function to find the square root of a number. This function belongs to the math
library, and the header file needs to be included in the program:
<code class="cpp">#include <cmath></code>
The following is the syntax for using the sqrt()
function to find the square root:
<code class="cpp">double y = sqrt(x);</code>
Where:
x
is the number to calculate the square root (must be a non-negative number). y
is the calculated square root value. Example:
Find the square root of the number 16:
<code class="cpp">#include <cmath> int main() { double number = 16; double squareRoot = sqrt(number); cout << "平方根为:" << squareRoot << endl; return 0; }</code>
Output:
<code>平方根为:4</code>
The above is the detailed content of How to use root sign in c++. For more information, please follow other related articles on the PHP Chinese website!