---
jupytext:
formats: md:myst
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: Python 3
language: python
name: python3
---Section Call By Semantics: Call By Value¶
This program demonstrates calling by value in Fortran.¶
program call_by_value
implicit none
integer :: n
n = 5
print *, n, "! = ", factorial(n)
print *
n = 6
print *, n, "! = ", factorial(n)
contains
function factorial(n) result(fac)
implicit none
integer, value :: n
integer :: fac
fac = 1
do while (n > 1)
fac = fac*n
n = n - 1
end do
end function factorial
end program call_by_valueThe above program is compiled and run using Fortran Package Manager (fpm):
Build the Program using FPM (Fortran Package Manager)¶
import os
root_dir = os.getcwd()code_dir = root_dir + "/" + "Fortran_Code/Section_Call_By_Semantics_Call_By_Value"os.chdir(code_dir)build_status = os.system("fpm build 2>/dev/null")Run the Program using FPM (Fortran Package Manager)¶
exec_status = os.system("fpm run 2>/dev/null") 5 ! = 120
6 ! = 720