Rem  Program: primtest.bas
Rem  Program to test whether a given integer is a Prime
print "PRIME NUMBER TESTER"
print "==================="
Do
   Input "Enter the integer to be tested:"; n
   If n = int(n) Then Exit Do
   print "Not a valid number"
Loop
n = abs(n)
Rem Test if 'n' is a prime.
Rem A number is a prime if n/2, n/3, n/4 ... n/sqrt(n) are not integers
msg1$ = "A Prime Number"
msg2$ = "Not A Prime Number"
if n = 0 then print msg2$ : end
if n = 1 then print msg1$ : end
maxdiv = sqr(n)
for i = 2 to maxdiv
  quot = n / i
  if(quot = int(quot)) then 'Not a prime number
      print msg2$ : end
  end if
next i
Rem Control will reach here only if the number is a prime
print msg1$
end
