アルゴリズム事典のarea.cからの移植です。ABの場合、変数の型を特に注意すべきです。
ActiveBasic 4.24.00で動作確認。
/***********************************************************
area.c -- 面積
***********************************************************/
Function area(n As Long, x As *Double, y As *Double) As Double
Dim i As Long
Dim a As Double
a = x[n - 1] * y[0] - x[0] * y[n - 1]
For i = 1 To n - 1
a += x[i - 1] * y[i] - x[i] * y[i - 1]
Next
area = 0.5 * a
End Function
'テストコード
#console
Dim x[3] As Double
x[0] = 1
x[1] = 4
x[2] = 2
x[3] = 0
Dim y[3] As Double
y[0] = 1
y[1] = 2
y[2] = 4
y[3] = 2
Print area(4, x, y)
Sleep(1000)
最終更新:2010年01月25日 19:28