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

How to type the root number in c++

下次还敢
Release: 2024-05-01 14:27:15
Original
603 people have browsed it

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>
Copy after login

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>
Copy after login

Output:

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

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!

Related labels:
c++
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