Pi: Difference between revisions

1,110 bytes added ,  2 years ago
Pi en Yabasic
(Added swift 4.2 code)
(Pi en Yabasic)
Line 5,865:
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745...
</pre>
 
 
=={{header|Yabasic}}==
{{trans|BASIC256}}
<lang yabasic>n = 1000
long = 10 * int(n / 4)
needdecimal = 1 //true
dim a(long)
nines = 0
predigit = 0 // {First predigit is a 0}
 
for j = 1 to long
a(j-1) = 2 // {Start with 2s}
next j
 
for j = 1 to n
q = 0
for i = long to 1 step -1
// {Work backwards}
x = 10*a(i-1) + q*i
a(i-1) = mod(x, (2*i - 1))
q = int(x / (2*i - 1))
next i
a(0) = mod(q, 10)
q = int(q / 10)
if q = 9 then
nines = nines + 1
else
if q = 10 then
d = predigit+1
gosub outputd
if nines > 0 then
for k = 1 to nines
d = 0
gosub outputd
next k
end if
predigit = 0
nines = 0
else
d = predigit
gosub outputd
predigit = q
if nines <> 0 then
for k = 1 to nines
d = 9
gosub outputd
next k
nines = 0
end if
end if
end if
next j
print predigit
end
 
label outputd
if needdecimal then
if d = 0 then return : fi
print d;
print ".";
needdecimal = 0 //false
else
print "", d;
endif
return</lang>
 
 
=={{header|zkl}}==
2,122

edits