<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--> </style> c fabs function, fabs() in c, c fabs() function with examples, fabs method, the fabs method in c
double fabs(double x); #where x should be in double
The fabs() function takes a single parameter in double. In case to find the absolute value of integer or float we can explicitly convert the number to double.
Parameter | Description | Required / Optional |
---|---|---|
double value | whose absolute value need to be find | Required |
The return value of fabs() function is a number in double.
Input | Return Value |
---|---|
double value | absolute value(in double) |
#include <stdio.h>
#include <math.h>
int main()
{
double k, output;
k = -3.70;
output = fabs(k);
printf("The |%.2lf| = %.2lf\n", k, output);
k = 9.20;
output = fabs(k);
printf("The |%.2lf| = %.2lf\n", k, output);
k = 0.10;
output = fabs(k);
printf("The |%.2lf| = %.2lf\n", k, output);
return 0;
}
Output:
The |-3.70| = 3.70 The |9.20| = 9.20 The |0.10| = 0.10
#include <stdio.h>
#include <math.h>
int main () {
int x, y;
x = 4325;
y = -122;
printf("Absolute value of %d is %lf\n", x, fabs(x));
printf("Absolute value of %d is %lf\n", y, fabs(y));
return(0);
}
Output:
Absolute value of 4325 is 4325.000000 Absolute value of -122 is 122.000000