DECLARE FUNCTION cruz! (x#, y#, cor!) ' Estima‡„o do valor de ă ' PP, 1997.01 ' PontosDentro = 0 PontosFora = 0 SCREEN 12 Pi# = 4 * ATN(1): ' PRINT Pi# ' PSET (20, 20) LINE (20, 20)-(320, 20) LINE (20, 20)-(20, 320) LINE (320, 20)-(320, 320) LINE (20, 320)-(320, 320) CIRCLE (20, 320), 300, 14, 0, 3.14159 / 2 LINE (330, 20)-(330, 320) LINE (330, 20)-(630, 20) LINE (330, 320)-(630, 320) LINE (630, 20)-(630, 320) CIRCLE (330, 320), 300, 14, 0, 3.14159 / 2 lado = 98 min# = 1# / (lado + 1) max# = 1# - min# + 9.999999999999999D-10 passo# = min# a = TIMER ' FOR x# = min# TO max# STEP passo# FOR x# = 0# TO 1# + .000000001# STEP passo# x2# = x# * x# ' FOR y# = min# TO max# STEP passo# FOR y# = 0# TO 1# + .000000001# STEP passo# ' IF SQR(x# * x# + y# * y#) < 1# THEN IF SQR(x2# + y# * y#) <= 1# THEN PontosDentro = PontosDentro + 1 lixo = cruz(20 + 300 * x#, 20 + 300 * (1 - y#), 2) ELSE PontosFora = PontosFora + 1 lixo = cruz(20 + 300 * x#, 20 + 300 * (1 - y#), 10) END IF NEXT y# NEXT x# LOCATE 24, 10 PRINT USING " ă ÷ #.######"; 4# * PontosDentro / (PontosDentro + PontosFora) b = TIMER LOCATE 25, 10 PRINT USING "##### pontos: ##.### secs"; PontosDentro + PontosFora; b - a LOCATE 26, 10 PRINT USING "###.## %"; (4# * PontosDentro / (PontosDentro + PontosFora) - Pi#) / Pi# * 100# Pontos = PontosDentro + PontosFora PontosDentro = 0 PontosFora = 0 b = TIMER RANDOMIZE TIMER FOR p = 1 TO Pontos x# = RND y# = RND IF SQR(x# * x# + y# * y#) < 1# THEN PontosDentro = PontosDentro + 1 lixo = cruz(330 + 300 * x#, 20 + 300 * (1 - y#), 2) ELSE PontosFora = PontosFora + 1 lixo = cruz(330 + 300 * x#, 20 + 300 * (1 - y#), 10) END IF NEXT p c = TIMER LOCATE 24, 50 PRINT USING " ă ÷ #.######"; 4# * PontosDentro / (PontosDentro + PontosFora) LOCATE 25, 50 PRINT USING "##### pontos: ##.### secs"; PontosDentro + PontosFora; b - a LOCATE 26, 50 PRINT USING "###.## %"; (4# * PontosDentro / (PontosDentro + PontosFora) - Pi#) / Pi# * 100# FUNCTION cruz (x#, y#, cor) PSET (x#, y#), cor PSET (x#, y# + 1), cor PSET (x#, y# - 1), cor PSET (x# + 1, y#), cor PSET (x# - 1, y#), cor END FUNCTION