000100* SIEVE OF ERATOSTHENES ******************************************||||||||
      * 2020-01-26
       IDENTIFICATION DIVISION.
         PROGRAM-ID. SIEVE-OF-ERATOSTHENES.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 STEPSIZE     PIC 999.
       01 TABLEPOINTER USAGE INDEX.
       01 START-AT     USAGE INDEX.
       01 SIEVE.
           05 SIEVECELL PIC 9 VALUE 1 USAGE BINARY OCCURS 10000 TIMES.
       PROCEDURE DIVISION.
           MOVE 0 TO SIEVECELL(1)
           MOVE 1 TO START-AT
           MOVE 1 TO TABLEPOINTER
           MOVE 1 TO STEPSIZE
           PERFORM UNTIL STEPSIZE IS GREATER THAN 100
               MOVE STEPSIZE TO TABLEPOINTER
      *        FIND THE FIRST PRIME NOT YET SIEVED WITH:
               PERFORM UNTIL EXIT
                   ADD 1 TO TABLEPOINTER
                   IF SIEVECELL(TABLEPOINTER) IS EQUAL TO 1 THEN
                       MOVE TABLEPOINTER TO STEPSIZE
                       EXIT PERFORM
                   END-IF
               END-PERFORM
               ADD STEPSIZE TO TABLEPOINTER
               PERFORM UNTIL TABLEPOINTER IS GREATER THAN 10000
                   MOVE 0 TO SIEVECELL(TABLEPOINTER)
                   ADD STEPSIZE TO TABLEPOINTER
               END-PERFORM
           END-PERFORM
           MOVE 0 TO TABLEPOINTER
           PERFORM 10000 TIMES
               ADD 1 TO TABLEPOINTER
               IF SIEVECELL(TABLEPOINTER) IS EQUAL TO 1
               THEN DISPLAY TABLEPOINTER
               END-IF
           END-PERFORM
           STOP RUN.