Home » C programs » math.h header file functions

Function fabs() to get the absolute value of a number in C

In this article, we are going to learn about the fabs() function of math.h header file and try to understand it with the help of an example.
Submitted by Manu Jemini, on March 30, 2018

In mathematics, certain situations demand the value to be absolute. This is very common and easy for human to get the absolute value. But in programming it will be a little tricky and anyway we will make a function in the end.

But there is a better way to do the same thing and then the math.h comes handy. This library has an inbuilt function which takes a double and returns the absolute value.

So to get it function running, just call this function with a library and store the result in another variable.

For Example: The absolute value of -21.0 is 21.0


    a = -3.0 
        if its negative, if true, multiple it by -1 
        else return the same number

This is a function from math.h file, therefore it needs that file to be included in the program.

math.h - fabs() function Example in C

#include <stdio.h>
#include <math.h>

int main()
	// Defining variables
	float a,b;

	// Assigning value for getting fabs value
	a = 30.33;

	// Calculating the fabs of the value a
	b = fabs(a);

	// Displaying the result for the user
	printf("The calculated absolute value is: %f \n\n", b);
	return 0;


math.h - fabs()  in c language

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com (2015-2018), Some rights reserved.

close Like other websites, this site uses cookies to deliver relevant ads based on your interest, by using our website, you acknowledge that you have read our privacy policy.