Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Prime Number Generator2

Keywords:   prime number generator

;Prime finder "Sieve of Erastophanes"
Decimals(1)
BoxOpen(0,"Prime Finder")
Maxprime=10000
PrimeList="1"
PrimeCount=1
list=ArrDimension(Maxprime+1)

ArrInitialize(list,1)
list[0]=0
list[1]=0


index=1
;or index=2 to MaxPrime
:loop
index=index+1
if index > MaxPrime then goto done
if list[index] == 0 then goto loop
BoxTitle(index)
BoxText(strcat("Cnt=",PrimeCount,"  %%=",(PrimeCount*100.0)/index))


Primelist=strcat(PrimeList," ",index)
PrimeCount=PrimeCount+1

xx=index
:woop
xx=xx+index
if xx > MaxPrime then goto loop
list[xx]=0
goto woop

goto loop

:done

AskItemList(strcat("Cnt=",PrimeCount,"  %%=",(PrimeCount*100.0)/index),PrimeList," ",@unsorted,@single)

Article ID:   W15218