RosettaCodeData/Task/Arithmetic-geometric-mean/FreeBASIC/arithmetic-geometric-mean.b...

27 lines
409 B
Plaintext

' version 16-09-2015
' compile with: fbc -s console
Function agm(a As Double, g As Double) As Double
Dim As Double t_a
Do
t_a = (a + g) / 2
g = Sqr(a * g)
Swap a, t_a
Loop Until a = t_a
Return a
End Function
' ------=< MAIN >=------
Print agm(1, 1 / Sqr(2) )
' empty keyboard buffer
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End