PROGRAM MatMult
   IMPLICIT NONE

   INTEGER, PARAMETER  :: Dim11 = 2, Dim12 = 3
   INTEGER, PARAMETER  :: Dim21 = 3, Dim22 = 4
   INTEGER, DIMENSION(Dim11,Dim12) :: Data1
   INTEGER, DIMENSION(Dim21,Dim22) :: Data2
   INTEGER, DIMENSION(Dim11,Dim22) :: Prod
   
   INTEGER             :: I, J, K, L

   
!        Just to put some values into the matrix 1
   DO I = 1, Dim11
      DO J = 1, Dim12
         Data1(I, J) = I + J
      END DO
   END DO

!        Just to put some values into the matrix 2
   DO I = 1, Dim21
      DO J = 1, Dim22
         Data2(I, J) = 2 * I + 2 * J
      END DO
   END DO

   IF ( Dim12 == Dim21) THEN 
   
   DO K = 1, Dim11
      DO L = 1, Dim22
         Prod(K,L) = 0
         DO I = 1 , Dim12
             Prod(K,L) = Prod(K,L) + Data1(K, I) * Data2(I, L)
         END DO
      END DO
   END DO
  
  
   WRITE(*,*)
   DO I = 1,Dim11
        WRITE(*,*) (Data1(I,J), J = 1, Dim12)   ! Printing 1
   END DO
   WRITE(*,*)

   DO I = 1, Dim21
     WRITE(*,*) (Data2(I,J), J = 1, Dim22)   ! Printing 2
   END DO
   WRITE(*,*)

   DO I = 1, Dim11
     WRITE(*,*) (Prod(I,J), J = 1, Dim22)   ! Printing Prod
   END DO

   ELSE
      WRITE(*,*) 'Product is not defined'
   END IF
END PROGRAM MatMult
