Problem: Write a Program to multiply two matrices of order l*m and m*n .
Program Test
implicit none
integer::l,m,n
Real::sum
integer,dimension(3,3)::a
integer,dimension(3,2)::b,c
read(*,10)((a(l,m),m=1,3),l=1,3)
10 format(3i3/3i3/3i3)
read(*,21)((b(m,n),n=1,2),m=1,3)
21 format(2i3/2i3/2i3)
do l=1,3
do n=1,2
sum=0.0
do m=1,3
sum=sum+a(l,m)*b(m,n)
c(l,n)=sum
end do
end do
end do
write(*,11)((a(l,m),m=1,3),l=1,3)
11 format(3i3/3i3/3i3)
write(*,12)((b(m,n),n=1,2),m=1,3)
12 format(/,/,/,2i3/2i3/2i3)
write(*,13)((c(l,n),n=1,2),l=1,3)
13 format(/,/,/,2i3/2i3/2i3)
stop
end
Program Test
implicit none
integer::l,m,n
Real::sum
integer,dimension(3,3)::a
integer,dimension(3,2)::b,c
read(*,10)((a(l,m),m=1,3),l=1,3)
10 format(3i3/3i3/3i3)
read(*,21)((b(m,n),n=1,2),m=1,3)
21 format(2i3/2i3/2i3)
do l=1,3
do n=1,2
sum=0.0
do m=1,3
sum=sum+a(l,m)*b(m,n)
c(l,n)=sum
end do
end do
end do
write(*,11)((a(l,m),m=1,3),l=1,3)
11 format(3i3/3i3/3i3)
write(*,12)((b(m,n),n=1,2),m=1,3)
12 format(/,/,/,2i3/2i3/2i3)
write(*,13)((c(l,n),n=1,2),l=1,3)
13 format(/,/,/,2i3/2i3/2i3)
stop
end
No comments:
Post a Comment