Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c++
communitycreator

What is llabs() in C++?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

llabs() is another type of abs() function in which both the type of input and output is long long int or long long. In other words, it can be considered as a long long int version of the abs() function.

The illustration below shows the C++ equivalent of the mathematical expression:

C++ representation of the mathematical expression

In order to use the llabs() function, we must include cstdlib in the program, as shown below:

#include <cstdlib>

Prototype

long long llabs(long long x)
long long int llabs(long long int x)

Parameter

This function takes in a single parameter of type long long or long long int.

Return value

llabs() returns the absolute value of long long or long long int sent as a parameter.

Code

#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
long long int number_1 = -2394545329003567669LL;
long long number_2 = -89187008890LL;
cout << "llabs(" << number_1 << ") = |" << number_1 << "| = " << llabs(number_1);
cout << endl;
cout << "llabs(" << number_2 << ") = |" << number_2 << "| = " << llabs(number_2);
return 0;
}

RELATED TAGS

c++
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring