| 请问为什么一直提示“Variable "n" masks variable in parent scope[行:9,列:18]”?当然不建议在返回单个数字的时候用interface,这段代码只是练习 
 [Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode program recursive_test
    implicit none
    INTEGER :: n
    interface
      RECURSIVE INTEGER function fact(n) result(ans)
        LOGICAL :: count
        INTEGER :: n
      end function fact
    end interface
    write (*, "('N = ', I3)")
    read (*, *) n
    write (*, "(I3, '! = ', I8)") n, fact(n)
    stop
  end program recursive_test
  RECURSIVE INTEGER function fact(n) result(ans)
    implicit none
    INTEGER :: n
    LOGICAL :: count
    if (n < 0) then
      ans = -999
      count = .false.
      return
    else if (n <= 1) then
      ans = 1
      count = .true.
      return
    end if
    ans = n*fact(n - 1)
    return
  end function fact
 
 
 |