The absolute value of a number in C++ can be obtained using the abs() function for integers and fabs() for floating-point numbers. These functions are available in <cmath> and <cstdlib>. Example usage:
cpp Copy Edit #include <iostream> #include <cmath> int main() { int a = -10; double b = -10.5; std::cout << "abs(-10) = " << abs(a) << std::endl; std::cout << "fabs(-10.5) = " << fabs(b) << std::endl; return 0;