English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Funzione di libreria <cmath> in C++
La funzione abs() in C++ restituisce il valore assoluto del parametro.
La funzione abs() e la funzione abs() in C++fabs()Identica.
La funzione è definita in<cmath>Definito nel file di intestazione.
[Matematica] |x| = abs(x) [Linguaggio C++]
double abs(double x); float abs(float x); long double abs(long double x); double abs(T x); // Per tipi interi
Nella funzione ABS() c'è un solo parametro e restituisce il valore del tipo double, float o long double.
La funzione abs() accetta un singolo parametro x e restituisce il valore assoluto.
La funzione abs() restituisce il valore assoluto di x, ovvero |x|.
#include <iostream> #include <cmath> using namespace std; int main() { double x = -87.91, result; result = abs(x); cout << "abs(" << x << ") = |" << x << "| = " << result << endl; return 0; }
Quando si esegue il programma, l'output è:
abs(-87.91) = |-87.91| = 87.91
#include <iostream> #include <cmath> using namespace std; int main() { long int x = -101; double result; result = abs(x); cout << "abs(" << x << ") = |" << x << "| = " << result << endl; return 0; }
Quando si esegue il programma, l'output è: