PROGRAM vecgen ! ! This program randomly generates an N-length vector V, and then ! places all elements of V that are <= 0.5 in the vector X, which ! is printed. ! IMPLICIT NONE INTEGER, PARAMETER :: N=10 INTEGER :: i, j DOUBLE PRECISION :: V(N), X(N) DOUBLE PRECISION, PARAMETER :: thresh = 0.5 CALL RANDOM_NUMBER(V) ! randomly generate array ! ! Look through entire V array, and add any elements below thresh to X ! j = 1 ! index in X to store into DO i = 1, N ! look through entire V array IF (V(i) .LE. thresh) THEN ! number is within threshold X(j) = V(i) ! put new number in X j = j + 1 ! increment X index END IF END DO j = j - 1 ! J now the number of numbers below thresh PRINT *, 'There were', j, ' numbers below the threshold:' if (j .LE. 10) PRINT *, X(:j) END PROGRAM vecgen