module common public :: initial,cross contains subroutine initial(a,b) real, dimension (:), intent(out) :: a,b a(1:3) = (/ 2.0, -3.0, -4.0 /) b(1:3) = (/ 6.0, 5.0, 1.0 /) end subroutine initial subroutine cross(r,s) real, dimension (:), intent(in) :: r,s real, dimension (3) :: cross_product ! note use of dummy variables integer :: component,i,j do component = 1,3 i = modulo(component,3) + 1 j = modulo(i,3) + 1 cross_product(component) = r(i)*s(j) - s(i)*r(j) end do print *, "" print *, "three components of the vector product:" print "(a,t10,a,t16,a)", "x","y","z" print *, cross_product end subroutine cross end module common program vector ! illustrate use of arrays use common real, dimension (3) :: a,b real :: dot call initial(a,b) dot = dot_product(a,b) print *, "dot product = ", dot call cross(a,b) end program vector