The QBasic Forum      Other Subforums, Links and Downloads
 Return to Index  

Not very accurate, but a start

March 13 2009 at 1:47 PM
lawgin  (no login)


Response to Calculate PI with the Monte Carlo algorithm

DEFDBL A-Z
x = .9
k = 3.999
DO
a = a + 1
FOR j = 1 TO 2
y = k * x * (1 - x)
p(j) = y * 10 ^ 6 - INT(y * 10 ^ 6)
x = y
NEXT
IF p(1) ^ 2 + p(2) ^ 2 < 1 THEN c = c + 1
LOOP WHILE a < 10 ^ 6
pi = 4 * c / a
PRINT pi
END

 
 Respond to this message   
Responses