/*REXX*/
/*--- ISPRIME - DETERMINE IF NUMBER IS PRIME - 1999 MARK MCDONALD ---*/
SAY "ENTER A NUMBER TO SEE IF IT IS A PRIME. ENTER 0 TO EXIT."
DO FOREVER
PULL TI
IF TI > 0 THEN DO
T = ISPRIME(TI)
IF T = 1 THEN SAY TI' IS A PRIME'
IF T = 0 THEN SAY TI' IS NOT A PRIME'
END
ELSE
EXIT
END
EXIT
ISPRIME: PROCEDURE
ARG LASTNO
IF LASTNO = 2 THEN RETURN 1
PRIME. = 1
DO N = 3 TO LASTNO BY 2
IF PRIME.N THEN DO
IF N = LASTNO THEN RETURN 1
DO K = N TO LASTNO BY N+N
PRIME.K = 0
END
END
END
RETURN 0