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      

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
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

6 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

6 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

6 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

9 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

1 year ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

1 year ago