Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Monte-Carlo-methods/FreeBASIC/monte-carlo-methods.basic
Normal file
33
Task/Monte-Carlo-methods/FreeBASIC/monte-carlo-methods.basic
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
' version 23-10-2016
|
||||
' compile with: fbc -s console
|
||||
|
||||
Randomize Timer 'seed the random function
|
||||
|
||||
Dim As Double x, y, pi, error_
|
||||
Dim As UInteger m = 10, n, n_start, n_stop = m, p
|
||||
|
||||
Print
|
||||
Print " Mumber of throws Ratio (Pi) Error"
|
||||
Print
|
||||
|
||||
Do
|
||||
For n = n_start To n_stop -1
|
||||
x = Rnd
|
||||
y = Rnd
|
||||
If (x * x + y * y) <= 1 Then p = p +1
|
||||
Next
|
||||
Print Using " ############, "; m ;
|
||||
pi = p * 4 / m
|
||||
error_ = 3.141592653589793238462643383280 - pi
|
||||
Print RTrim(Str(pi),"0");Tab(35); Using "##.#############"; error_
|
||||
m = m * 10
|
||||
n_start = n_stop
|
||||
n_stop = m
|
||||
Loop Until m > 1000000000 ' 1,000,000,000
|
||||
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue