abs ()- 計算整數絕對值
格式
#include <stdlib.h>
int abs(int n);
語言層次
ANSI
安全執行緒
是
說明
abs()
函數會傳回整數引數 n的絕對值。
回覆值
沒有錯誤回覆值。 當引數的絕對值無法以整數表示時,結果未定義。 最小可容許整數的值由 INT_MIN 在 <limits.h> 併入檔中定義。
範例
此範例計算整數 x 的絕對值,並將它指派給 y。
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int x = -4, y;
y = abs(x);
printf("The absolute value of x is %d.\n", y);
/********************* Output **************************
The absolute value of x is 4.
*****************************************************/
}