fabs Arithmetic function in C programming Language
- Home
- pre-define maths function in C
- fabs Arithmetic function in C programming Language
- On
- By
- 0 Comment
- Categories: pre-define maths function in C
fabs Arithmetic function in C programming Language
fabs Arithmetic function in C programming Language
We will learn about fabs Arithmetic function in C programming Language
In the C Programming Language, the fabs() arithmetic function returns the absolute value of a floating point.
Declaration
Syntax
The syntax of the fabs() function in the C programming Language
double fabs(double x);
parameters or Argument
x is the parameter or argument of this function to convert to an absolute value;
Return value
When a value is passed for x, this function returns the absolute value of x
Required Header
In the C Language, the required header file for fabs() function is
#include <math.h>
Example
The following example explains the usage of fabc() function
Program 1
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
double a=345.93,b=-57.34;//assign variables
printf("the absolute value of a: %f\n",fabs(a));
printf("te absolute value of b: %f\n",fabs(b));
//display fabs values of given value
return 0;
}
When the above program is compiled and run, it will produce the following result
the absolute value of a:345.930000
the absolute value of a:57.340000
Program 2
#include <stdio.h>
#include <math.h>
int main()
{
double value1, value2,result1,result2;//declare local variable
printf("Enter the positive float value :");
scanf("%lf",&value1);//get input for value1
printf("Enter the Negative float value :");
scanf("%lf",&value2);//get input for value1
result1=fabs(value1);//find and assign absolute value to result1
result2=fabs(value2);//find and assign absolute value to result1
printf("fabs value of %lf is : %.2lf\n",value1,result1);
printf("fabs value of %lf is : %.2lf\n",value2,result2);
//display result of given values
getch();
return 0;
}
When the above program is compiled and run , it will produce the following result
Enter the positive float value: 45.65 Enter the positive float value: -34.67 fabs value of 45.650000 is : 45.65 fabs value of 34.670000 is : 34.67
Similar Functions
Other C programming language functions that are similar to the cosine function
suggested for you
User defined function in C language
Arithmetic functions in C Language