Jump to content

Recommended Posts

Posted

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

Guest
This topic is now closed to further replies.
×
×
  • Create New...

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.