Hacker News new | past | comments | ask | show | jobs | submit login

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




Sorry, I need to learn how to post code here.


    program 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


Put 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: