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

OK Here

March 13 2009 at 3:49 PM
qbguy  (no login)


Response to Calculate PI with the Monte Carlo algorithm


DIM X AS DOUBLE, Y AS DOUBLE, M AS LONG, N AS LONG
RANDOMIZE TIMER
CLS
DO
X = RND(1&)
Y = RND(1&)
IF X * X + Y * Y <= 1 THEN M = M + 1
N = N + 1
PI = 4 * M / N
PRINT PI
LOOP


It gets 3.14 right at least very fast.

 
 Respond to this message   
Responses