!----- Ex6_8: Eratosthenes Sieve (with use of Array Functions) ----- INTEGER, ALLOCATABLE :: index(:) INTEGER :: lim = 0, n DO WHILE( lim <= 1 ) PRINT*, 'Upper limit?'; READ*, lim END DO ALLOCATE( index(lim) ) index = (/ 0, (n, n= 2, lim) /) DO n = 2, INT( lim**0.5 ) IF( index(n) == 0 ) CYCLE index( n**2 : lim : n ) = 0 END DO PRINT '(I5, A)', COUNT(index/=0), " prime numbers are found." PRINT '(10I6)', PACK( index, index/=0 ) END