abs,labs.fabs関数
コード #include <iostream> #include <cmath> using namespace std; void main() { //int型の絶対値 int nNum = -10; printf("nNum = %d\n", abs(nNum)); //long型の絶対値 long lNum = -100; printf("lNum = %d\n", labs(lNum)); //double型の絶対値 double dNum = -1000.0; printf("dNum = %f\n", fabs(dNum)); return; }
結果 nNum = 10 lNum = 100 dNum = 1000.000000