Site icon Codeforcoding

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      

cosh function   in C  language                               

sinh function in C language

tanh function in C language

abs function in C language

floor function in C language

ceil function in C language

round function in C language

sqrt function in C language

pow function in C language

exp function in C language

log function in C language

log10 function in C language

trunc function in C language

 

 

suggested for you

Function in C language

User defined function in C language

Arithmetic functions in C Language

String function in C language

 

abs Arithmetic function in C programming language
labs Arithmetic function in C programming language
Exit mobile version