Skip to content

Instantly share code, notes, and snippets.

@JeffIrwin
Created September 29, 2020 21:14
Show Gist options
  • Save JeffIrwin/28b26ca8e69d49a0ddb558ae3a319889 to your computer and use it in GitHub Desktop.
Save JeffIrwin/28b26ca8e69d49a0ddb558ae3a319889 to your computer and use it in GitHub Desktop.
Hot take: an array is a function
module mymodule
integer, parameter :: n = 6
integer, parameter :: myarray(n) = [1, 1, 2, 3, 5, 8]
contains
integer function myfunc(input)
integer :: input, i, j, k
myfunc = 1
i = 1
j = 1
do k = 1, input - 2
myfunc = i + j
i = j
j = myfunc
end do
end function myfunc
end module mymodule
program array
use mymodule
integer :: i
write(*,*) '========================='
write(*,*) ' array , function'
write(*,*) '========================='
do i = 1, n
write(*,*) myarray(i), ',', myfunc(i)
end do
write(*,*) '========================='
end program array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment