Microsoft KB Archive/39188

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 17:56, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


TIMER Example; Sieve of Eratosthenes Prime Number Correction

Article ID: 39188

Article Last Modified on 11/21/2006

This article was previously published under Q39188

SUMMARY

On Page 333 of the "Microsoft QuickBASIC for Apple Macintosh: BASIC Language Reference", the TIMER function Example (the Sieve of Eratosthenes benchmark program) is supposed to find prime numbers. However, it mistakenly finds some numbers that are not actually prime.

The Sieve of Eratosthenes benchmark program on Page 333 should be replaced with the version below, which correctly returns only prime numbers.

MORE INFORMATION

The replacement program is as follows:

defint a-z
size=8191
dim flags(8191)
count=0
for i=2 to size
  flags(i)=-1
next
for i=2 to sqr(size)
  if flags(i) then
    for k=i*i to size step i
      flags(k)=0
    next
  end if
next

for i=0 to size
  if flags(i) then print i; : count = count + 1
next
print
print count; "primes"
while mouse(0): wend
                


Additional query words: MQuickB

Keywords: KB39188