* ////////////////////////////////////////////////////////// * // Name: Peter M. Maurer * // Program: Sieve of Eratosthenes * // Due: Never * // Language: COBOL * ////////////////////////////////////////////////////////// identification division. program-id. SieveE as "SieveE.SieveE". environment division. configuration section. repository. data division. working-storage section. 77 i pic 99999. 77 j pic 99999. 77 Product pic 99999. 77 Showit pic ZZZZZ. 77 Candidates pic 99999 occurs 999. procedure division. Main_Part. Move 1 to I. Perform Init_1 999 times. Move 0 to Candidates(1). * start the sieve with the integer 1 Move 1 to i. Perform Check_Number Until i >= 1000. Move 1 to i. Perform Print 999 times. goback. Init_1. Move 1 to Candidates(i). Add 1 to I. Check_Number. * advance to the next un-crossed out number. * this number must be a prime. Perform Advance Until i >= 1000 or Candidates(i) NOT = 0. * Avoid running off the end of the data structure. if i >= 1000 EXIT. Move 2 to j. Multiply i by j giving Product. * cross out all multiples of the prime, starting with 2*p. Perform Cross_Out Until Product >= 1000. * go on to next prime. Add 1 to i. Advance. Add 1 to i. Cross_Out. Move 0 to Candidates(Product). Add 1 to j. Multiply i by j giving Product. Print. if Candidates(i) NOT = 0 Move i to Showit Display Showit, " is prime.". Add 1 to i. end program SieveE.