labs ()-llabs ()- 計算 Long 和 Long Long Integer 的絕對值

格式 (labs())

#include <stdlib.h>
long int labs(long int n);

格式 (llabs())

#include <stdlib.h>
long long int llabs(long long int i);

語言層次

ANSI

安全執行緒

說明

labs() 函數會產生其長整數引數 n的絕對值。 當引數等於最小可用長整數 LONG_MIN時,結果可能未定義。 值 LONG_MIN 定義在 <limits.h> 併入檔中。

llabs() 函數會傳回其 long long 整數運算元的絕對值。 當引數等於最小可用長整數 LONG_LONG_MIN時,結果可能未定義。 值 LONG_LONG_MIN 定義在 <limits.h> 併入檔中。

回覆值

labs() 函數會傳回 n的絕對值。 沒有錯誤回覆值。

llabs() 函數會傳回 i的絕對值。 沒有錯誤回覆值。

範例

此範例會將 y 計算為長整數 -41567 的絕對值。
#include <stdlib.h>
#include <stdio.h>
 
int main(void)
{
   long x, y;
 
   x = -41567L;
   y = labs(x);
 
   printf("The absolute value of %ld is %ld\n", x, y);
}
 
/********************  Output should be similar to:  **************
 
The absolute value of -41567 is 41567
*/

相關資訊