编辑代码

program test_cross_product
  implicit none
  real :: a(3), b(3), c(3)

  ! 初始化向量a和b
  a = (/1.0, 0.0, 0.0/)
  b = (/0.0, 1.0, 0.0/)

  ! 计算叉积
  call cross_product(a,b,c)

  ! 输出结果
  write(*,'("c = (",f5.2,",",f5.2,",",f5.2)")') c(1), c(2), c(3)
end program test_cross_product

subroutine cross_product(a,b,c)
  implicit none
  real :: a(3), b(3), c(3)
  c(1) = a(2)*b(3) - a(3)*b(2)
  c(2) = a(3)*b(1) - a(1)*b(3)
  c(3) = a(1)*b(2) - a(2)*b(1)
end subroutine cross_product