C 庫函數– abs()
描述
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