Jump to content

Computing Pi Using Rectangles

Featured Replies

Here's a program I wrote in Structured Basic on my C64 computer:

 

100 REM COMPUTING PI USING RECTANGLES

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:B=1

280 .....N=10

300 ENDPROC

320 :

340 PROC MAIN

360 .....DX=(B-A)/N

380 .....PRINT:PRINT"DX =";DX

400 .....X=-DX

420 .....I=-1

440 .....PRINT:PRINT" I ";" X ";" Y ";" T ":PRINT

460 .....LOOP

480 ........I=I+1

500 ........X=X+DX

520 ........Y=SQR(1-X*X)

540 ........T=T+Y

560 ........PRINT I;X;Y;T

580 .....UNTIL I=N-1

600 .....PI=DX*T*4

620 ENDPROC

640 :

660 PROC OUTPUT

680 .....PRINT:PRINT"PI =";PI

700 .....PRINT:PRINT"TIME TAKEN = ";TI$

720 ENDPROC

!

Moderator Note

Isaac, you already have a number of threads on calculating pi. From now on, could you please consolidate them to one thread instead of opening up others?

For reference:

http://www.sciencefo...__1#entry679038
http://www.sciencefo...__fromsearch__1
http://www.sciencefo...__fromsearch__1
http://www.sciencefo...__fromsearch__1
http://www.sciencefo...__fromsearch__1
http://www.sciencefo...__fromsearch__1
http://www.sciencefo...__fromsearch__1

There are far too many of these. I am merge the non-repeating threads into the last of these links so you can use the single thread for your ideas, etc., on calculating pi.

Thread closed.

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.