Section Arrays: Array Arithmetic#
Adapted from: gjbex/Fortran-MOOC
This program demonstrates array arithmetic.#
program array_arithmetic
implicit none
real, dimension(5) :: A = [ 1.2, 2.3, 3.4, 4.5, 5.6 ], &
B = [ -1.0, -0.5, 0.0, 0.5, 1.0], &
C
print *, "The array A contains: "
print *, A
print *
print *, "The array B contains: "
print *, B
print *
C = A + 2.0*B
print *, "C = A + 2.0 * B"
print *, "The array C contains: "
print *, C
end program array_arithmetic
The above program is compiled and run using Fortran Package Manager (fpm):
import os
root_dir = os.getcwd()
code_dir = root_dir + "/" + "Fortran_Code/Section_Arrays_Array_Arithmetic"
os.chdir(code_dir)
build_status = os.system("fpm build 2>/dev/null")
exec_status = os.system("fpm run 2>/dev/null")
The array A contains:
1.20000005 2.29999995 3.40000010 4.50000000 5.59999990
The array B contains:
-1.00000000 -0.500000000 0.00000000 0.500000000 1.00000000
C = A + 2.0 * B
The array C contains:
-0.799999952 1.29999995 3.40000010 5.50000000 7.59999990