! Eratosthenes Sieve ( with use of array functions ) PROGRAM ex6_8 IMPLICIT NONE INTEGER, ALLOCATABLE :: index(:) INTEGER :: lim = 0, n DO WHILE( lim <= 1 ) PRINT '(1X, A)', 'Upper limit?' READ *, lim END DO ALLOCATE( index(1:lim) ) index = (/ 0, ( n, n = 2, lim ) /) DO n = 2, INT( lim ** 0.5E0 ) IF ( index(n) == 0 ) CYCLE index(n**2:lim:n) = 0 END DO PRINT '(1X, I5, A)', COUNT( index /= 0 ), ' prime numbers are found.' PRINT '(1X, 10I6)', PACK( index, index /= 0 ) END PROGRAM ex6_8