Practical Fortran
Dot Product
Built-in Reduction
dot_product multiplies two same-shape arrays element-wise and sums the result.
Program
Play the program to compute the dot product of two real vectors.
dot_product.f90
program dot_product_demo
implicit none
real :: x(3), y(3)
real :: d
x = [1.0, 2.0, 3.0]
y = [4.0, 5.0, 6.0]
d = dot_product(x, y)
print '(F0.1)', d
end program dot_product_demo
dot_product
`dot_product(x, y)` returns `sum(x * y)` for vectors.
real array
`real :: x(3)` declares a length-3 real vector.
F0.1
`F0.1` prints a real with one decimal and no extra width.