De functie labs () in C ++ retourneert de absolute waarde van lange of lange int-gegevens.
De labs () -functie kan worden beschouwd als de long int
versie van abs ().
Het wordt gedefinieerd in het header-bestand.
(Wiskunde) | x | = labs (x) (C ++ programmeren)
labs () prototype (vanaf C ++ 11-standaard)
lange labs (lange x); long int labs (long int x);
De functie labs () accepteert één argument van het type long
of long int
en retourneert een waarde van hetzelfde type.
labs () Parameters
x: een lange of lange int-gegevens waarvan de absolute waarde wordt geretourneerd.
labs () Retourwaarde
De functie labs () retourneert de absolute waarde van x ie | x |.
Voorbeeld: hoe werkt de functie labs () in C ++?
#include #include using namespace std; int main() ( long int x,y; x = -9999999L; y = 10000000L; cout << "labs(" << x << ") = |" << x << "| = " << labs(x) << endl; cout << "labs(" << y << ") = |" << y << "| = " << labs(y) << endl; return 0; )
Wanneer u het programma uitvoert, is de uitvoer:
labs (-9999999) = | -9999999 | = 9999999 labs (10000000) = | 10000000 | = 10000000