C++中有两个库函数下有对应的求绝对值的函数:
#include<iostream> #include<stdlib.h> using namespace std; int main() { int a=-1; cout<<abs(a); return 0; }
输出即为a的绝对值1。
#include<iostream> #include<math.h> using namespace std; int main() { int a=-1; cout<<fabs(a); return 0; }
原文:https://www.cnblogs.com/ManbaDF99/p/12299748.html