Code archives/Algorithms/Prime Finder

This code has been declared by its author to be Public Domain code.

Download source code

Prime Finder by Nathaniel
(Posted 20 years ago)
The program first asks which number to start calculating to see if it is prime. It then continues with the next consecutive number. (It does this until you press the esc. key.) I don't suggest putting in a number that's over 5000.

Have Fun!
;Prime Finder
;Created by: Bubble Boy

Graphics 800,600,16,2
SetBuffer BackBuffer()

AppTitle "Prime Finder"

number#=1
divisor#=1
quotient#=0
rounded=0
prime=0
go=0


Color 250,250,86
Print "PRIME FINDER"

number#=Input$("What number do you want me to start with? ")


While Not KeyHit(1)

Color 250,250,86
Print number#
Flip

While go = 0

   quotient# = number# / divisor#
   rounded=Int( quotient# )

   Color 50,255,50
   Print quotient# + " = " + number# + " / " + divisor#


   If divisor# > 1
   If quotient# = rounded
      prime = 0
      go = 1
   Else 
      prime = 1

   End If   
   End If


Delay 20

If KeyDown(1)
   End
End If

If divisor# = number#
   prime = 1
   go = 1
End If

If number# = 1
   prime = 0
   go = 1
End If

divisor# = divisor# + 1




Wend

If prime = 1
   Color 250,250,86
   Print number#
   Color 255,50,50
   Print "PRIME"

   Flip()


Else If prime = 0
   Color 250,250,86
   Print number#
   Color 50,50,255
   Print "NOT PRIME"
   Flip()
End If
Print " "

Delay 2000

go=0
prime=0
number#=number# + 1
divisor#=1
quotient#=0

Wend

End