Sieve of Eratosthenes: Difference between revisions
Content deleted Content added
Sieve of Eratosthenes in various BASIC dialents (BASIC256, QBasic and True BASIC) |
|||
Line 1,814: | Line 1,814: | ||
110 IF p(n)=0 THEN PRINT n;", "; |
110 IF p(n)=0 THEN PRINT n;", "; |
||
120 NEXT n</lang> |
120 NEXT n</lang> |
||
==={{header|QBasic}}=== |
|||
{{works with|QBasic|1.1}} |
|||
{{works with|QuickBasic|4.5}} |
|||
<lang qbasic>limit = 120 |
|||
DIM flags(limit) |
|||
FOR n = 2 TO limit |
|||
flags(n) = 1 |
|||
NEXT n |
|||
PRINT "Prime numbers less than or equal to "; limit; " are: " |
|||
FOR n = 2 TO SQR(limit) |
|||
IF flags(n) = 1 THEN |
|||
FOR i = n * n TO limit STEP n |
|||
flags(i) = 0 |
|||
NEXT i |
|||
END IF |
|||
NEXT n |
|||
FOR n = 1 TO limit |
|||
IF flags(n) THEN PRINT USING "####"; n; |
|||
NEXT n</lang> |
|||
{{out}} |
|||
<pre>Prime numbers less than or equal to 120 are: |
|||
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113</pre> |
|||
==={{header|BASIC256}}=== |
|||
<lang BASIC256>arraybase 1 |
|||
limit = 120 |
|||
dim flags(limit) |
|||
for n = 2 to limit |
|||
flags[n] = True |
|||
next n |
|||
print "Prime numbers less than or equal to "; limit; " are: " |
|||
for n = 2 to sqr(limit) |
|||
if flags[n] then |
|||
for i = n * n to limit step n |
|||
flags[i] = False |
|||
next i |
|||
end if |
|||
next n |
|||
for n = 1 to limit |
|||
if flags[n] then print rjust(n,4); |
|||
next n</lang> |
|||
{{out}} |
|||
<pre>Prime numbers less than or equal to 120 are: |
|||
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113</pre> |
|||
==={{header|True BASIC}}=== |
|||
{{trans|QBasic}} |
|||
<lang qbasic>LET limit = 120 |
|||
DIM flags(0) |
|||
MAT redim flags(limit) |
|||
FOR n = 2 to limit |
|||
LET flags(n) = 1 |
|||
NEXT n |
|||
PRINT "Prime numbers less than or equal to "; limit; " are: " |
|||
FOR n = 2 to sqr(limit) |
|||
IF flags(n) = 1 then |
|||
FOR i = n*n to limit step n |
|||
LET flags(i) = 0 |
|||
NEXT i |
|||
END IF |
|||
NEXT n |
|||
FOR n = 1 to limit |
|||
IF flags(n)<>0 then PRINT using "####": n; |
|||
NEXT n |
|||
END</lang> |
|||
{{out}} |
|||
<pre>Same as QBasic entry.</pre> |
|||
==={{header|QL SuperBASIC}}=== |
==={{header|QL SuperBASIC}}=== |