3 ms·
Here is a Fortran 95 program to compute the factorial of 0 through 5. The factorial can be computed as the product of an array created on the fly, without an ex
by poster123 8y ago
Here is a Fortran 95 program to compute the factorial of 0 through 5. The factorial can be computed as the product of an array created on the fly, without an explicit loop.
program xfact
integer :: i
print*,fact([(i,i=0,5)])
contains
elemental function fact(n)
integer, intent(in) :: n
integer :: i,fact
fact = product([(i,i=1,n)])
end function fact
end program xfact
- poster123 8y agoSorry, I need to learn how to post code here.
- Jtsummers 8y agoPut two spaces in front of the content you want to appear as a code block (two spaces in front of each line): this version respects line breaks while this version does not respect line breaks.
- pjmlp 8y agoprogram xfact integer::i print *, fact ([(i, i = 0, 5)]) contains elemental function fact (n) integer, intent (in)::n integer::i fact = product ([(i, i = 1, n)]) end function fact end program xfact