program assign2_1
implicit none
integer :: i,j,k
integer, allocatable :: a(:,:),b(:,:),c(:,:)
allocate(a(2,2),b(2,2),c(2,2))
a=reshape((/1,2,3,5/),(/2,2/))
b=reshape((/3,1,4,8/),(/2,2/))
print*,'A matrix'
do i=1,2
   print*,a(i,:)
enddo
print*,'B matrix'
do i=1,2
   print*,b(i,:)
enddo
c=matmul(a,b)
print*,'C matrix = AB using matmul'
do i=1,2
   print*,c(i,:)
enddo
c=0
do i=1,2
   do j=1,2
      do k=1,2
         c(i,j)=c(i,j)+a(i,k)*b(k,j)
      enddo
   enddo
enddo
print*,'C matrix = AB using loops'
do i=1,2
   print*,c(i,:)
enddo
print*,'C matrix = A+B using loops'
c = a + b
do i=1,2
   print*,c(i,:)
enddo
print*,'Sum of all elements in A matrix =',sum(a)
print*,'Sum of the first column in A matrix =',sum(a(:,1))
print*,'Sum of the second column in A matrix =',sum(a(:,2))
print*,'First column in A matrix',a(:,1)
!print*,sum(a,mask=a>5) ! for absoft compiler
print*,'Count elements > 5 in A+B matrix =',count(c>5) ! for intel compiler
print*,'Sum of elements > 5 in A+B matrix =',sum(c,c>5) ! for intel compiler
end program assign2_1