C ++ cmath abs () - C ++ standaardbibliotheek

De functie abs () in C ++ geeft de absolute waarde van het argument terug.

De abs-functie is identiek aan fabs () in C ++.

De functie is gedefinieerd in het header-bestand.

(Wiskunde) | x | = abs (x) (C ++ programmeren)

abs () prototype (vanaf C ++ 11-standaard)

dubbele buikspieren (dubbele x); zweven abs (zweven x); lange dubbele buikspieren (lange dubbele x); dubbele buikspieren (T x); // Voor integraal type

De functie abs () draait één argument en een waarde van het type retourneert double, floatof long doubletype.

abs () Parameters

De functie abs () accepteert één argument, x waarvan de absolute waarde wordt geretourneerd.

abs () Retourwaarde

De functie abs () geeft de absolute waarde van x ie | x | terug.

Voorbeeld 1: Hoe werkt de functie abs () in C ++?

 #include #include using namespace std; int main() ( double x = -87.91, result; result = abs(x); cout << "abs(" << x << ") = |" << x << "| = " << result << endl; return 0; ) 

Wanneer u het programma uitvoert, is de uitvoer:

abs (-87,91) = | -87,91 | = 87,91

Voorbeeld 2: abs () functie voor integraal typen

 #include #include using namespace std; int main() ( long int x = -101; double result; result = abs(x); cout << "abs(" << x << ") = |" << x << "| = " << result << endl; return 0; ) 

Wanneer u het programma uitvoert, is de uitvoer:

abs (-101) = | -101 | = 101

Interessante artikelen...