Prime Number - identifies primes

This program identifies whether a number is prime.

NOTE: this program cannot handle 0, 1, or 2, which are special cases.

PROGRAM: PRIME
:ClrHome
:Prompt X
:-1 -> Y
:For(P,2,sqrt(X) + 1)
:If fPart(X/P) * P = 0
:Then
:P -> Y
:Goto E
:End
:End
:Lbl E
:If Y does not = -1

([Use the symbol does not equal, located in the [Test] menu accessed by pressing [2nd] [MATH])

:Then
:Disp X
:Disp "Is not prime"
:Disp "Divideable by"
:Disp Y
:End
:If Y = -1
:Then
:Disp X
:Disp "Is prime"
:End

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License