---------------------------------------------------------------------------------------------------------------------------------------
PROGRAM matrix
IMPLICIT NONE
INTEGER::m1,n1,m2,n2,t,k1,k2,i,k,j
REAL,ALLOCATABLE::a(:,:),b(:,:),c(:,:),c1(:),c2(:)
REAL::s
PRINT*
PRINT*," _ _ _ _ _ _ "
PRINT*," | a11 a12 ..a1n1 | | b11 b12 ..b1n2 | | c11 c12 ..c1n2 | "
PRINT*," | | | | | | "
PRINT*," | a21 a22 ..a2n1 | X | b21 b22 ..b2n2 | = | c21 c22 ..c2n2 | "
PRINT*," | . | | . . . | | . . . | "
PRINT*," | . | | . . . | | . . . | "
PRINT*," |_am11 am12..am1n1_| |_bm21 bm22..bm2n2_| |_cm11 cm12..cm1n2_| "
PRINT*," m1xn1 m2xn2 m1xn2 "
PRINT*
PRINT*,"------------------------------------------------------------------------"
PRINT*
PRINT*,"input m1 and n1 : "
READ*,m1,n1
PRINT*,"input m1 and n2 : "
READ*,m2,nIF (n1/=m2) THEN
PRINT*," n1 must be equal m2"
PRINT*
STOP
END IF
ALLOCATE(a(m1,n1),b(m2,n2),c(m1,n2),c1(n1),c2(m2))
PRINT*
DO k1=1,m1
PRINT*,"input line",k1,"of matrix a :"
READ*,a(k1,:)
END DO
DO k2=1,m2
PRINT*,"input line",k2,"of matrix b :"
READ*,b(k2,:)
END DO
DO i=1,m1
DO j=1,n2
c1=a(i,:)
c2=b(:,j)
s=0.
DO k=1,m2
s=s+(c1(k)*c2(k))
END DO
PRINT*
c(i,j)=s
END DO
END DO
PRINT*," C(",m1,",",n2,") :"
PRINT*
DO t=1,m1
PRINT*," ",c(t,:)
END DO
PRINT*
END PROGRAM