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
else
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 http://www.cplusplus.com/doc/tutorial/functions/
(On second thoughts, maybe not: it tells you the answer there!)