C 庫函數 - abs()

C 標準庫 - <stdlib.h> C 標準庫 - <stdlib.h>

描述

C 庫函數 int abs(int x) 返回 x 的絕對值。

聲明

下麵是 abs() 函數的聲明。

int abs(int x)

參數

  • x -- 完整的值。

返回值

該函數返回 x 的絕對值。

實例

下麵的實例演示了 abs() 函數的用法。

#include <stdio.h>
#include <stdlib.h>

int main ()
{
   int a, b;

   a = abs(5);
   printf("a 的值 = %d\n", a);

   b = abs(-10);
   printf("b 的值 = %d\n", b);

   return(0);
}

讓我們編譯並運行上面的程式,這將產生以下結果:

a 的值 = 5
b 的值 = 10

C 標準庫 - <stdlib.h> C 標準庫 - <stdlib.h>