Home > Backend Development > C++ > How to type the root number in C language

How to type the root number in C language

下次还敢
Release: 2024-04-29 21:09:13
Original
367 people have browsed it

In C language, use the sqrt() function to find the root. This function receives a floating point number and returns its square root. Correct usage: #include <math.h>, sqrt(double x);

How to type the root number in C language

## Find the root number in C language

In C language, you can use the following symbols to find the root:

sqrt().

Usage:

sqrt() The function receives a floating-point number as a parameter and returns the square root of the number. Its syntax is as follows:

<code class="c">double sqrt(double x);</code>
Copy after login

Example:

The following code example demonstrates how to use the

sqrt() function in C language:

<code class="c">#include <math.h>

int main() {
  double x = 4.0;
  double y = sqrt(x);
  printf("x 的平方根为:%f\n", y);
  return 0;
}</code>
Copy after login
Output:

<code>x 的平方根为:2.000000</code>
Copy after login

Note:

    ##sqrt()
  • The function can only handle positive floating point numbers. If the argument is negative, NaN (not a number) is returned.
  • sqrt()
  • The function returns a floating point type value, even if the argument is an integer. Before using the
  • sqrt()
  • function, you need to include the <math.h> header file.

The above is the detailed content of How to type the root number in C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template