abs difference c++ code example
Example 1: how to find absolute value in c++
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int x = -5;
long y = -2371041;
int a = abs(x);
long b = abs(y);
cout << "abs(" << x << ") = |" << x << "| = " << a << endl;
cout << "abs(" << y << ") = |" << y << "| = " << b << endl;
}
Example 2: abs in cpp
int a =4;
int b =5;
int ans = abs(a-b);
Example 3: absolute difference c++
val1 = abs(22);
val2 = abs(-43);
cout << "abs(22) = " << val1 << "\n";
cout << "abs(-43) = " << val2 << "\n";