Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's Texas Code Snippets.
IsPrime
A simple program to determine wether a number is prime. It is not the optimal way to calculate if a number is prime.
The code in the Texas TI-84 might look like this:
: ClrHome
:
: Prompt X
:
: -1->Y
:
: For(I,2,√(X)+1)
:
: If fPart(X/I)=0.0
: Then
: I->Y
: Goto E
: End
:
: End
:
: Lbl E:
:
: If Y≠-1
: Then
: Disp X
: Disp "IS NOT PRIME"
: Disp "DIVIDABLE BY"
: Disp Y
: Else
: Disp X
: Disp "IS PRIME"
: End
: