Guest User

Untitled

a guest
Sep 7th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Integer :: a
  2.  
  3. a = 5
  4. print *, a, "fat(a) = ", fat(a)
  5. print *, a, "fat(a) = ", fatR(a)
  6.  
  7. Contains
  8.  
  9. function fat(a) result (f)
  10. Integer, Intent(In) :: a
  11. Integer :: i
  12. f = 1
  13.  
  14. Do i=1,a
  15.         f = f*i
  16. EndDo
  17.  
  18. end function
  19.  
  20. recursive function fatR(a) result (f)
  21. Integer, Intent(In) :: a
  22. Integer :: i
  23.  
  24. if (a .le. 1) then
  25.         f = 1
  26. else
  27.         f = a*fatR(a-1)
  28. endif
  29.  
  30. end function
  31. end
Add Comment
Please, Sign In to add comment