Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Integer :: a
- a = 5
- print *, a, "fat(a) = ", fat(a)
- print *, a, "fat(a) = ", fatR(a)
- Contains
- function fat(a) result (f)
- Integer, Intent(In) :: a
- Integer :: i
- f = 1
- Do i=1,a
- f = f*i
- EndDo
- end function
- recursive function fatR(a) result (f)
- Integer, Intent(In) :: a
- Integer :: i
- if (a .le. 1) then
- f = 1
- else
- f = a*fatR(a-1)
- endif
- end function
- end
Add Comment
Please, Sign In to add comment