Home > Backend Development > C++ > How to use root sign in c++

How to use root sign in c++

下次还敢
Release: 2024-05-01 14:24:13
Original
1015 people have browsed it

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 <cmath>, double number = 16, double squareRoot = sqrt(number), cout << "The square root is:" << squareRoot << endl; .

How to use root sign in c++

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:

#include <cmath>
Copy after login

The following is the syntax for using the sqrt() function to find the square root:

double y = sqrt(x);
Copy after login

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:

#include <cmath>

int main() {
  double number = 16;
  double squareRoot = sqrt(number);
  cout << "平方根为:" << squareRoot << endl;

  return 0;
}
Copy after login

Output:

<code>平方根为:4</code>
Copy after login

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!

Related labels:
c++
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template