| 1 | ! CHECK: 3628800 |
| 2 | program test_factorial |
| 3 | implicit none |
| 4 | integer :: n, result |
| 5 | n = 10 |
| 6 | result = factorial(n) |
| 7 | print *, result |
| 8 | contains |
| 9 | recursive function factorial(n) result(f) |
| 10 | integer, intent(in) :: n |
| 11 | integer :: f |
| 12 | if (n <= 1) then |
| 13 | f = 1 |
| 14 | else |
| 15 | f = n * factorial(n - 1) |
| 16 | end if |
| 17 | end function |
| 18 | end program |
| 19 |