Pi: Difference between revisions

1,623 bytes added ,  1 year ago
Pi in Chipmunk Basic, GW-BASIC and MSX Basic
(Pi in Chipmunk Basic, GW-BASIC and MSX Basic)
Line 700:
3.14159265358979323846264338327950288419716939937510582097494459230781...
</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{works with|Applesoft BASIC}}
{{works with|MSX_BASIC}}
{{works with|QBasic}}
{{trans|Applesoft BASIC}}
<syntaxhighlight lang="qbasic">100 REM adopted from Applesoft BASIC
110 n = 100 : rem n may be increased, but will slow execution
120 ln = int(10*n/3)+16
130 nd = 1
140 dim a(ln)
150 n9 = 0
160 pd = 0 : rem First pre-digit is a 0
170 rem
180 for j = 1 to ln
190 a(j-1) = 2 : rem Start wirh 2S
200 next j
210 rem
220 for j = 1 to n
230 q = 0
240 for i = ln to 1 step -1 : rem Work backwards
250 x = 10*a(i-1)+q*i
260 a(i-1) = x-(2*i-1)*int(x/(2*i-1)) : rem X - Int ( X / Y) * Y
270 q = int(x/(2*i-1))
280 next i
290 a(0) = q-10*int(q/10)
300 q = int(q/10)
310 if q = 9 then n9 = n9+1 : goto 510
320 if q <> 10 then goto 440
330 rem Q == 10
340 d = pd+1 : gosub 560
350 if n9 <= 0 then goto 400
360 for k = 1 to n9
370 d = 0 : gosub 560
380 next k
390 rem End If
400 pd = 0
410 n9 = 0
420 goto 510
430 rem Q <> 10
440 d = pd : gosub 560
450 pd = q
460 if n9 = 0 then goto 510
470 for k = 1 to n9
480 d = 9 : gosub 560
490 next k
500 n9 = 0
510 next j
520 print str$(pd)
530 end
540 rem
550 rem Output digits
560 if nd = 0 then print str$(d); : return
570 if d = 0 then return
580 print str$(d);".";
590 nd = 0
600 return</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
Line 757 ⟶ 815:
</syntaxhighlight>
 
==={{header|Integer BasicGW-BASIC}}===
{{works with|PC-BASIC|any}}
The [[#Chipmunk_Basic|Chipmunk Basic]] solution works without any changes.
 
==={{header|Integer Basic}}===
Integer version was derived from the Pascal_spigot without any optimisation. It is more than 33% faster than the Applesoft version since it runs natively with integers.
 
Line 808 ⟶ 869:
</syntaxhighlight>
 
==={{header|OsborneMSX 1 MBASICBasic}}===
The [[#Chipmunk_Basic|Chipmunk Basic]] solution works without any changes.
 
==={{header|Osborne 1 MBASIC}}===
Osborne 1 program is slightly different to allow it to keep the numbers all on the main screen rather than scrolling off to the right...
 
2,139

edits