You are on page 1of 2

program Matrices !

This program is used to multiply matrices Integer n,A(100,100), B(100,100), C(100,100),d,e 11 print*, "Input the dimension of the square matrices" read*, n do i=1,n do j=1,n print*, "Input the",i,"row",",",j,"column","entry for MATRIX A" read*, A(i,j) end do end do print*,"The MATRIX A is:" do i=1,n print*, (A(i,j), j=1,n) end do do i=1,n do j=1,n print*, "Input the",i,"row",",",j,"column","entry for MATRIX B" read*, B(i,j) end do end do print*,"The MATRIX B is:" do i=1,n print*, (B(i,j), j=1,n) end do 10 print*, "Do you want to get the sum, difference, product of the matrices? Press 1 for SUM, 2 for DIFFERENCE, and 3 for PRODUCT." read*, d if (d==1) then do i=1,n do j=1,n C(i,j)=A(i,j)+B(i,j) end do end do print*, "The sum of the matrices is:" do i=1,n print*, (C(i,j), j=1,n) end do else if (d==2)then do i=1,n do j=1,n C(i,j)=A(i,j)-B(i,j) end do end do print*, "The difference of the matrices is:" do i=1,n print*, (C(i,j), j=1,n)

end do else if (d==3) then do i=1,n do j=1,n C(i,j)=0 do k=1,n C(i,j)=C(i,j)+A(i,k)*B(k,j) end do end do end do print*, "The product of the matrices is:" do i=1,n print*, (C(i,j), j=1,n) end do else print*, "you have inputted an invalid number." goto 10 end if print*, "Do you want to use this program again? PRESS 1 if YES. Otherwise, press any number." read*,e if (e==1) then go to 11 else print*,"THANK YOU FOR USING THIS PROGRAM." end if end

You might also like