ABS(絕對值函式)

ABS(絕對值函式)

ABS是絕對值函式,頭檔案是stdlib.h

基本介紹

  • 中文名:ABS
  • 外文名:absolute value
  • 頭檔案:stdlib.h
  • 用 法:int abs(int i)
  • 用途:絕對值函式
C語言用詞,功能,函式,Pascal,Logo用詞,格式,解釋,示例,VC++語言用詞,VB語言用詞,語法,說明,lisp,Java語言用詞,JavaScript,

C語言用詞

函式名: abs

功能

頭檔案:stdlib.h
用 法: int abs(int i);
程式例:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int number = -1234;
printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}
在C語言中還有fabs,也是求絕對值的。(Java語言中有類似的作用。)

函式

格式:Abs(<數值表達式>)
功能:求表達式絕對值
說明:函式返回值類型與數值表達式的數據類型相同
例如:Abs(-3.7),其值為3.7。
C語言中的abs有區別。

Pascal

Function Abs( X : Real ) : Longint;
功 能: 求數的絕對值
例:
Begin
{ 語句; { ( X數據類型 ) 輸出結果 } }
Writeln( Abs(-111222333) ); {(Longint) 111222333 }
Writeln( Abs(-1112223334324445556) ); {(Int64) 1112223334324445556 }
End.
Matlab
求複數實部與虛部的平方和的算術平方根
格式:abs(x)
例如:x=1+j;
y=abs(x);
>>y=1.4142

Logo用詞

格式

ABS 數字

解釋

ABS:求輸入數字的絕對值。

示例

?ABS -30
結果:30
ABS 30
結果:30
ABS -3 + -4
結果:7

VC++語言用詞

abs()僅對整型求絕對值
對浮點數求絕對值使用fabs()函式。
Example
/* 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

VB語言用詞

返回參數的絕對值,其類型和參數相同。

語法

Abs(number)
必要的number參數是任何有效的數值表達式,如果number包含Null,則返回Null,如果number是未初始化的變數,則返回 0。

說明

一個數的絕對值是將正負號去掉以後的值。例如,ABS(-1)和ABS(1)都返回1

lisp

(abs <數>) 返回<數>的絕對值。
(abs (* -1 2)) 返回值為 2 。

Java語言用詞

在Math中使用。
語法
Math.abs(數字)
如:
int num = -24;
int b = Math.abs(num);
// 結果:b = 24

JavaScript

如何使用 abs() 來取得數的絕對值。
<html><body><scripttype="text/javascript">document.write(Math.abs(7.25)+"<br/>")document.write(Math.abs(-7.25))</script></body></html>

相關詞條

熱門詞條

聯絡我們