English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
La funzione sqrt() in C++ restituisce la radice quadrata del numero.
√x = sqrt(x)
Questa funzione è disponibile in<cmath>Definito nel file di intestazione.
double sqrt(double x); float sqrt(float x); long double sqrt(long double x); double sqrt(T x); // per interi
La funzione sqrt() accetta un singolo parametro non negativo.
Se si passa un parametro negativo alla funzione sqrt(), si verifica un errore.
La funzione sqrt() restituisce la radice quadrata del parametro fornito.
#include <iostream> #include <cmath> using namespace std; int main() { double x = 10.25, result; result = sqrt(x); cout << "La radice quadrata di 10.25 è " << result << endl; return 0; }
运行程序时,输出为:
La radice quadrata di 10.25 è 3.20156
#include <iostream> #include <cmath> using namespace std; int main() { long x = 464453422; double result = sqrt(x); cout << "平方根是 464453422的" << result << endl; return 0; }
运行程序时,输出为:
平方根是21551.2 464453422