TI-BASIC:Guess Number

From Learn @ Cemetech
Jump to navigationJump to search

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