Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PROGRAM Matrizen2
- IMPLICIT NONE ! allow no implicit types
- ! constant integers
- INTEGER, PARAMETER :: Ni = 3, Nj = 4, Nk = 100, MAXR = 4
- ! arrays of float64 value, initialized to zero
- DOUBLE PRECISION :: A(Ni, Nk) = 0, B(Ni, Nj) = 0, C(Ni, Nj) = 0
- ! loop counters
- INTEGER :: i, j, k
- ! fill in random numbers in interval [0, 1]
- CALL RANDOM_NUMBER(A)
- CALL RANDOM_NUMBER(B)
- ! make random integers
- A = FLOOR(1 + A * MAXR) ! rand-int [1, 4]
- B = FLOOR(B * Nk) ! rand-int [0, Nk]
- ! NOTE: array index starts from 1
- DO i = 1, Ni
- DO j = 1, Nj
- k = INT(B(i, j))
- C(i, j) = A(i, k)
- PRINT '(A2,I0,A1,I0,A4,F6.3)', 'B[', i, ',', j, '] = ', B(i, j)
- PRINT '(A2,I0,A1,I0,A4,F6.3)', 'A[', i, ',', k, '] = ', A(i, k)
- PRINT '(A2,I0,A1,I0,A4,F6.3)', 'C[', i, ',', j, '] = ', C(i, j)
- PRINT *
- END DO
- END DO
- END PROGRAM Matrizen2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement