C fabs () - C Standard Library

De functie fabs () retourneert de absolute waarde van een getal.

Functieprototype van fabs ()

 dubbele fabs (dubbele x);

De functie fabs () accepteert één argument (in double) en retourneert de absolute waarde van dat getal (ook in double).

(Wiskunde) | x | = fabs (x) (in C-programmering)

Om de absolute waarde van een geheel getal of een float te vinden, kunt u het getal expliciet naar dubbel converteren.

int x = 0; dubbel resultaat; resultaat = fabs (dubbel (x));

De functie fabs () is gedefinieerd in het header-bestand math.h

Voorbeeld: C fabs () functie

 #include #include int main() ( double x, result; x = -1.5; result = fabs(x); printf("|%.2lf| = %.2lf", x, result); x = 11.3; result = fabs(x); printf("|%.2lf| = %.2lf", x, result); x = 0; result = fabs(x); printf("|%.2lf| = %.2lf", x, result); return 0; )

Uitvoer

| -1.50 | = 1,50 | 11,30 | = 11.30 | 0.00 | = 0,00

Interessante artikelen...