c语言中取绝对值是哪个函数
1. C语言的库函数中提供了求绝对值的函数,函数名为 abs
2. 函数的头文件:#include
3. 函数原型:int abs (int j);
4. 函数说明:abs()用来计算参数j 的绝对值,然后将结果返回。
5. 返回值:返回参数j 的绝对值结果。
c语言中取绝对值的函数
* ABS.C: This program computes and displays
* the absolute values of several numbers.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void main( void )
{int ix = -4, iy;
long lx = -41567L, ly;
double dx = -3.141593, dy;
iy = abs( ix );
printf( "The absolute value of %d is %d/n", ix, iy);
ly = labs( lx );
printf( "The absolute value of %ld is %ld/n", lx, ly);
dy = fabs( dx );
printf( "The absolute value of %f is %f/n", dx, dy );
Output
The absolute value of -4 is 4
The absolute value of -41567 is 41567
The absolute value of -3.141593 is 3.141593
函数名: abs 功 能: 求整数的绝对值 头文件:math.h
函数原型:int abs(int i);
程序例:
#include <stdio.h>
#include <math.h>
int main(void)
{ int number = -1234;
printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}