代码:
#include <stdio.h>#include <math.h>int main(){int ix = -10;long lx = -100000L;long long llx = -10000000000LL;printf_s("The absolute value of %d is %dn", ix, abs(ix));printf_s("The absolute value of %ld is %ldn", lx, labs(lx));printf_s("The absolute value of %lld is %lldn", llx, llabs(llx));return 0;} 2.计算浮点自变量的绝对值 语法: double fabs(double x);float fabsf(float x);long double fabsl(long double x); 要求:必需头文件<math.h> 例:分别用fabs,fabsf,fabsl函数对三个数取绝对值代码:
#include <stdio.h>#include <math.h>int main(){float fx = -0.00123;double dx = -0.000000000123;long double ldx = -0.0000000000000000000123;printf_s("The absolute value of %g is %gn", fx, fabsf(fx));printf_s("The absolute value of %g is %gn", dx, fabs(dx));printf_s("The absolute value of %g is %gn", ldx, fabsl(ldx));return 0;}