Home  >  Article  >  Backend Development  >  How to type the root number in c++

How to type the root number in c++

下次还敢
下次还敢Original
2024-05-01 14:27:15546browse

In C, the root sign can be calculated through the sqrt() function, which accepts floating-point number parameters and returns its square root: Function call syntax: double sqrt(double x); Parameters: The floating-point number x to calculate the square root; Return value: The square root of x if x is nonnegative; otherwise NaN (not a number).

How to type the root number in c++

The root number in C

In C, you can use sqrt() Function calculates the root. This function accepts a floating point number as argument and returns its square root.

Use sqrt()Function

Syntax:

<code class="cpp">double sqrt(double x);</code>

Parameters:

  • x: The floating point number to calculate the square root

Return value: The square root of

  • x, if x is not Negative number; otherwise returns NaN (not a number)

Example:

<code class="cpp">#include <iostream>
#include <cmath>

int main() {
  double number = 9.0;
  double square_root = sqrt(number);

  std::cout << "平方根为:" << square_root << std::endl;

  return 0;
}</code>

Output:

<code>平方根为:3</code>

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

Statement:
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