Program 01
C PROGRAM FOR PRODUCT OF TWO MATRICES
DIMENSION MAT1(5,5),MAT2(5,5),C(5,5)
INTEGER MAT1,MAT2,C,R1,C1,R2,C2
WRITE(*,*)'ENTER THE ORDER OF FIRST MATRIX'
READ(*,*)R1,C1
WRITE(*,*)'ENTER THE ORDER OF SECOND MATRIX'
READ(*,*)R2,C2
IF(C1.NE.R2)THEN
WRITE(*,*)'PRODUCT NOT POSSIBLE,ENTER ORDERS ONCE AGAIN'
GOTO 11
ENDIF
WRITE(*,*)'ENTER THE ELEMENTS OF FIRST MATRIX'
READ(*,*)((MAT1(I,J),J=1,C1),I=1,R1)
WRITE(*,*)'ENTER THE ELEMENTS OF SECOND MATRIX'
READ(*,*)((MAT2(I,J),J=1,C2),I=1,R2)
DO 10 I=1,R1
DO 10 J=1,C2
C(I,J)=0
DO 10 K=1,C1
C(I,J)=C(I,J)+MAT1(I,K)*MAT2(K,J)
10 CONTINUE
WRITE(*,*)'PRODUCT OF ABOVE MATRICES IS'
DO 20 I=1,R1
WRITE(*,*)(C(I,J),J=1,C2)
20 CONTINUE
11 STOP
End
-----------------------------------------------------------------------------------
Program 02
c A FORTRAN program to find out the product of two matrices
c Designed by ...
dimension mat1(5,5),mat2(5,5),c(5,5)
integer mat1,mat2,c,r1,c1,r2,c2
99 write(*,*)'This is program to find out the product of two given ma
+trices'
write(*,15)
15 format(/)
write(*,*)'Enter the order of first matrix'
read(*,*)r1,c1
write(*,*)'Enter the order of second matrix'
read(*,*)r2,c2
if(c1.ne.r2)then
write(*,*)'Product is not possible'
write(*,*)'Reason=> column number of the first matrix is not equal
+to the row number of second'
goto 11
endif
write(*,*)'Enter the element of first matrix'
read(*,*)((mat1(i,j),j=1,c1),i=1,r1)
write(*,*)'Enter the elements of second matrix'
read(*,*)((mat2(i,j),j=1,c2),i=1,r2)
do 10 i=1,r1
do 10 j=1,c2
c(i,j)=0
do 10 k=1,c1
c(i,j)=c(i,j)+mat1(i,k)*mat2(k,j)
10 continue
write(*,*)'Product is'
do 20 i=1,r1
write(*,*)(c(i,j),j=1,c2)
20 continue
11 write(*,*)'Would you like to multiply another pair of matrices?'
write(*,*)'1) YES ....PRESS 1'
write(*,*)'2) NO ....PRESS 2'
read(*,*)n
if(n.eq.1) then
goto 99
endif
End