module factorialModule
  implicit none
contains
  integer function factorial(n)
    implicit none
    integer,intent(in)::n
    integer::i,fact
    
    fact=1
    do i=1,n
      fact=fact*i
    enddo
    factorial=fact
  end function factorial

  integer function combin(n,r)
    implicit none
    integer,intent(in)::n,r
    integer::Cnr
    if(0<=r .and. r<=n) then
      Cnr=factorial(n)/factorial(r)/factorial(n-r)
    else
      Cnr=0
    endif
    combin=Cnr
  endfunction combin
end module factorialModule
