pre-define maths function in C

labs Arithmetic function in C programming language

labs Arithmetic function in C programming language

We will learn this tutorial about labs Arithmetic function in C programming language

In the C Programming Language, the labs() is an arithmetic function, which returns the absolute value of a long integer

Declaration

Syntax

The syntax of  the labs() function in the C programming Language

long int labs(long int x);

parameters or Argument

x of the parameter or argument of this function for find absolute value of given long integer value

Return value

when passing a value for x, this function returns the absolute value of x

Required Header

In the C Language, the required header file for labs() function is

#include <math.h>

Example

Program 1

The following example explains the usage of fabc() function

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long int a=659644L, b=-129888854L;
    printf("Absolute value of a : %ld\n",labs(a));
    printf("Absolute value of b : %ld\n",labs(b));
    getch();
    return 0;
}

 

When compile and run above program, this will produce the following result

absolute value of a:659644
absolute value of a:129888654

 

 

Program 2

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    long int m,n,o,p;//diclare of local  variable
    printf("Enter the long positive number\n");
    //get input positive
    scanf("%ld",&n);
    printf("Enter the long Negative number\n");
    //get input negative
    scanf("%ld",&o);
    m=labs(n);//assign absolute value of n to m
    p=labs(o);//assign absolute value of o to p
    printf("absolute value of the positive value is: %ld\n",m);
    printf("absolute value of the Negative value is: %ld",p);
//display labs values of given values
    getch();
    return 0;
}

When compile and run above program, this will produce the following result

Enter the long positive number
456783
Enter the long positive number
-542334
absolute value of te positive value is:456783
absolute value of the negative value is:542334

 

Other C programming language functions that are  similar to the fabs() function

abs () function in c language

fabs() function in c language

floor() function in C language

round() 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

 

 

fabs Arithmetic function in C programming Language
floor 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

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago