49 lines
1.1 KiB
COBOL
49 lines
1.1 KiB
COBOL
IDENTIFICATION DIVISION.
|
|
PROGRAM-ID. primes.
|
|
AUTHOR. Dan Ballard.
|
|
|
|
DATA DIVISION.
|
|
WORKING-STORAGE SECTION.
|
|
01 Cnt PIC S9(10) VALUE 3.
|
|
01 TMax PIC S9(10) VALUE 3.
|
|
01 I PIC S9(10) VALUE 0.
|
|
01 isp PIC S9(10) VALUE 1.
|
|
01 tmp PIC S9(10) VALUE 1.
|
|
01 break PIC 9 VALUE 0.
|
|
01 MAX PIC S9(10) VALUE 20.
|
|
01 SQT PIC S9(10) VALUE 4.
|
|
01 SQ PIC S9(10) VALUE 2.
|
|
|
|
PROCEDURE DIVISION.
|
|
Main.
|
|
ACCEPT MAX
|
|
IF MAX < 1
|
|
DISPLAY "Invalid Max Num"
|
|
EXIT
|
|
END-IF
|
|
PERFORM UNTIL Cnt > MAX
|
|
MOVE 3 TO I
|
|
MOVE 0 TO break
|
|
MOVE 1 TO isp
|
|
|
|
PERFORM UNTIL I > SQ OR break = 1
|
|
MOVE Cnt TO isp
|
|
DIVIDE Cnt BY i GIVING tmp REMAINDER isp
|
|
IF isp = 0
|
|
MOVE 1 TO break
|
|
END-IF
|
|
ADD 2 TO I
|
|
END-PERFORM
|
|
|
|
IF NOT isp = 0
|
|
DISPLAY Cnt
|
|
END-IF
|
|
|
|
ADD 2 TO Cnt
|
|
IF Cnt > SQT
|
|
ADD 1 TO SQ
|
|
MULTIPLY SQ BY SQ GIVING SQT
|
|
END-IF
|
|
END-PERFORM
|
|
STOP RUN.
|