乘以兩個數組我試圖乘用FORTRAN兩個數組,下面是我的代碼在FORTRAN
program multiplyarray
implicit none
! Declare Variables
integer, dimension(2,3 :: first_array
integer, dimension(3,2) ::second_array
integer, dimension(2,2) :: resultant_array
integer:: i, j, a, b, k, product
! Generating values for array
a = 2
do i = 1,2
do j = 1,3
first_array(i,j) = a
a = a + 2
end do
end do
print*,first_array
do i = 1,3
do j = 1,2
b = 0
second_array(i,j) = b
b = b + 3
end do
end do
! Multiplying both arrays
do i = 1,2
do j = 1,2
do k = 1,3
product = product + first_array(i,k) * second_array(k,j)
end do
resultant_array (j,i) = product
end do
end do
! Displaying the resultant matrix
do i = 1,2
do j = 1,2
print *,resultant_array(i,j)
end do
end do
end program multiplyarray
可能是什麼錯誤?我沒有得到個體矩陣,所以我可以乘他們得到結果矩陣。第一矩陣是0,而第二矩陣的結果也爲0
會發生什麼?你的結果是什麼?任何錯誤消息?哪些錯誤消息? –
你需要初始化'產品' – agentp