PROGRAM PRIMES !Program: Lists all prime numbers from 2 up to an arbitrarily !chosen number "N". Method used: Ancient "Sieve of Eratosthenes" !and a well known theorem in number theory that every composite !(i.e., not prime) number has a prime number factor less than or !equal to the square root of the number itself. The number !"NMAX=10000000" below is arbitrary and may need to be reduced in !the program because of your specific computer memory and Fortran !compiler limitations. As a note, the code can be easily !re-written to save the numbers in an array and to write that !array to a hard disk file. ! !Author: Dr. Jerry R. Ziemke PARAMETER (NMAX=10000000) REAL Q(NMAX) WRITE(*,*) 'Enter N (0 < N <= 10,000,000):' READ(*,*) X N=IFIX(X) WRITE(*,*) 'Prime numbers:' DO I=1,N Q(I)=1. ENDDO DO I=2,N IF (Q(I).EQ.1.) THEN J=1 DO WHILE ((I*J).LE.N) Q(I*J)=0. j=j+1 ENDDO WRITE(*,*) I ENDIF ENDDO STOP END