Home »
C++ programming language
llabs() Function with Example in C++
C++ llabs() function: Here, we are going to learn about the llabs() function with example of cstdlib header in C++ programming language.
Submitted by IncludeHelp, on May 28, 2020
C++ llabs() function
llabs() function is a library function of cstdlib header. It used to get the absolute of the given value. This function is similar to the abs() and labs() functions except for the type of the parameter, it is used for the long long integer values. It accepts a parameter and returns the absolute value.
Syntax
Syntax of llabs() function:
C++11:
long long int llabs (long long int n);
Parameter(s)
- n – represents the value whose absolute value to found.
Return value
The return type of this function is long long int, it returns the absolute value.
Sample Input and Output
Input:
n = -1234567890987654321
Function call:
llabs(n);
Output:
1234567890987654321
Input:
n = 1234567890987654321
Function call:
llabs(n);
Output:
1234567890987654321
Example
C++ code to demonstrate the example of llabs() function:
// C++ code to demonstrate the example of
// llabs() function
#include <iostream>
#include <cstdlib>
using namespace std;
// main() section
int main()
{
long long int n;
n = -1234567890987654321;
cout << "llabs(" << n << "): " << llabs(n) << endl;
n = 1234567890987654321;
cout << "llabs(" << n << "): " << llabs(n) << endl;
n = -1111222233334444555;
cout << "llabs(" << n << "): " << llabs(n) << endl;
n = 1111222233334444555;
cout << "llabs(" << n << "): " << llabs(n) << endl;
return 0;
}
Output
llabs(-1234567890987654321): 1234567890987654321
llabs(1234567890987654321): 1234567890987654321
llabs(-1111222233334444555): 1111222233334444555
llabs(1111222233334444555): 1111222233334444555
Reference: C++ llabs() function