IsaacAsimov Posted May 23, 2012 Posted May 23, 2012 Here's a program I wrote in Structured BASIC on my C64 computer: 100 REM COMPUTING PI USING TRAPEZOIDS 110 REM DOTS REPRESENT INDENTATIONS 120 CALL INIT 140 CALL MAIN 160 CALL OUTPUT 180 END 200 : 220 PROC INIT 240 .....TI$="000000" 260 .....A=0 280 .....B=1 300 .....X%=1 320 .....N=10 340 ENDPROC 360 : 380 PROC MAIN 400 .....DX=(B-A)/N 420 .....PRINT:PRINT "DX =";DX 440 .....DX=-DX 460 .....I=-1 480 .....PRINT:PRINT" I ";" X ";" Y ";" T":PRINT 500 .....LOOP 520 ..........I=I+1 540 ..........X=X+DX 560 ..........D=1-X*X 580 ..........REM 600 ..........IF D<0 620 ..............D=0 640 ..........ENDIF 660 ..........REM 680 ..........Y=2*SQR(D) 700 ..........IF I=0 OR I=N 720 ..............Y=Y/2 740 ..........ENDIF 760 ..........T=T+Y 780 ..........PRINT I;X;Y;T 800 .....UNTIL I=N 820 .....PI=DX/2*T*4 840 ENDPROC 860 : 880 PROC OUTPUT 900 .....PRINT:PRINT"PI =";PI 920 .....PRINT:PRINT"TIME TAKEN = ";TI$ 940 ENDPROC
hypervalent_iodine Posted May 25, 2012 Posted May 25, 2012 ! Moderator Note Closed as a duplicate of another thread, which was merged into this:http://www.scienceforums.net/topic/66297-sneaky-method-of-estimating-pi/
Recommended Posts