[Fortran] 纯文本查看 复制代码
program ex0831
implicit none
integer ::n
write(*,*)'N='
read (*,*)n
write(*,"(I2,'!=',I8)")n,fact(n)
stop
end
contains
recursive integer function fact(n)result(ans)
implicit none
integer ,intent(in)::n
if (n<0)then
ans=-1
return
else if (n<=1)then
ans =1
return
end if
ans=n*fact(n-1)
return
end function fact
end
[Fortran] 纯文本查看 复制代码
program ex0831
implicit none
integer ::n
write(*,*)'N='
read (*,*)n
write(*,"(I2,'!=',I8)")n,fact(n)
contains
recursive integer function fact(n) result(ans)
integer ,intent(in)::n
if (n<0)then
ans=-1
else if (n<=1)then
ans =1
else
ans=n*fact(n-1)
end if
end function fact
end program ex0831