what is the program to print factorial???
Last edited on
program test
   implicit none
   integer, external :: factorial
   integer N

   print *, "Enter N"
   read *, N
   print *, "N! =", factorial( N )

end program test

recursive integer function factorial( N ) result( ans )
   implicit none
   integer, intent(in) :: N

   if ( N == 0 ) then
      ans = 1
      ans = N * factorial( N - 1 )
   end if

end function factorial

Or were you looking for it in C++?

I think the idea is that you have a go at it yourself first, @champ195. You can make it a lot slicker in c++: probably about half that number of lines.
Have a look at functions and, in particular, "recursivity" in
(On second thoughts, maybe not: it tells you the answer there!)
Last edited on
! gets so big so fast that a lookup table is sufficient and much better performance.

so just

vector<const unsigned long long> fact = {1,1,2,6, .... blah blah

Topic archived. No new replies allowed.