#include#include int main() { double num = -5.6; double abs_num = std::fabs(num); std::cout << "The absolute value of " << num << " is " << abs_num << std::endl; return 0; }
#includeThis example is similar to the previous one, but it uses a float variable instead of a double. The result is also printed to the console. Both of these examples use the cmath library, which is a standard library in C++. The cmath library provides a set of mathematical functions that can be used to perform calculations involving numbers.#include int main() { float num = -3.14; float abs_num = std::fabs(num); std::cout << "The absolute value of " << num << " is " << abs_num << std::endl; return 0; }