integer, external :: factorial
print *, "Enter N"
read *, N
print *, "N! =", factorial( N )
end program test
recursive integer function factorial( N ) result( ans )
integer, intent(in) :: N
if ( N == 0 ) then
ans = 1
ans = N * factorial( N - 1 )
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 http://www.cplusplus.com/doc/tutorial/functions/
(On second thoughts, maybe not: it tells you the answer there!)