Read
the following two matrices from an INPUT file
i) Calculate AB
Program Coding
program Qu_01
implicit
none
integer:: i, j, k
integer:: A(3,4), B(4,2), AB(3,2), C(3,4)
open(unit=1, file="input.dat")
open(unit=2, file="output.dat")
do i=1, 3
read(1, 7) (A(i,j), j=1,4)
7 format(4(I2, 1x))
end do
do i=1, 4
read(1, 8) (B(i, j), j=1,2)
8 format(2(I2, 1x))
end do
do i=1,3 !row of AB
do j=1,2 !column of AB
AB(i,
j)=0.0
do k=1, 4 !column of A or Row of B
AB(i,
j)=AB(i,j) + A(i,k)*B(k, j) !Product of A and
B
end do
end do
end do
write(2, 9) "i) AB matrix is ="
9
format(A18)
do i=1,3
write(2,10) (AB(i,j), j=1, 2)
10 format(2(i4, 1x))
end do
do i=1,3
do j=1,4
C(i,j)=
A(i,j)*A(i,j)
end do
end do
write(2, 11) "ii) C matrix is ="
11 format(/,A19)
do i=1,3
write(2,12) (C(i,j), j=1, 4)
12 format(4(i4, 1x))
end
do
end program
No comments:
Post a Comment