RosettaCodeData/Task/Trabb-Pardo-Knuth-algorithm/FreeBASIC/trabb-pardo-knuth-algorithm.freebasic

38 lines
572 B
Text
Raw Permalink Normal View History

2017-09-23 10:01:46 +02:00
' version 22-07-2017
2016-12-05 23:44:36 +01:00
' compile with: fbc -s console
Function f(n As Double) As Double
2017-09-23 10:01:46 +02:00
return Sqr(Abs(n)) + 5 * n ^ 3
2016-12-05 23:44:36 +01:00
End Function
' ------=< MAIN >=------
2017-09-23 10:01:46 +02:00
Dim As Double x, s(1 To 11)
2016-12-05 23:44:36 +01:00
Dim As Long i
2017-09-23 10:01:46 +02:00
For i = 1 To 11
2016-12-05 23:44:36 +01:00
Print Str(i);
Input " => ", s(i)
Next
Print
Print String(20,"-")
2017-09-23 10:01:46 +02:00
i -= 1
Do
2016-12-05 23:44:36 +01:00
Print "f(" + Str(s(i)) + ") = ";
x = f(s(i))
If x > 400 Then
2017-09-23 10:01:46 +02:00
Print "-=< overflow >=-"
2016-12-05 23:44:36 +01:00
Else
Print x
End If
2017-09-23 10:01:46 +02:00
i -= 1
Loop Until i < 1
2016-12-05 23:44:36 +01:00
' empty keyboard buffer
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End