作者sjgau (sjgau)
看板Fortran
标题Re: [问题] subroutine 和 function 的差别?
时间Tue Oct 7 20:41:36 2008
以下的 call xxx(),
xxx() 都是 副程式,subroutine
至於,为何不使用 function 的形式,
这是 见仁见智的问题,
要是由我来写这两个 副程式,
我也是会 写成 subroutine
random_seed() 是建立 虚拟乱数系列的 种子数,
random_number() 是产生 0.0 to 0.999 的乱数,
x >= 0.0, and x < 1.0
program VF1007
USE DFLIB
implicit none
real x, sum
integer no, i
no= 10e+6 + 0.5
sum= 0.0
call random_seed()
do i=1, no
call random_number(x)
sum= sum + x
end do
print *, 'ave= ', sum/no
end program VF1007
※ 引述《shelling (shelling)》之铭言:
: 新手上路
: 请教一下 subroutine 和 function 这两个宣告方式有什麽不同呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.231.5.90
1F:→ sjgau:ave 会趋近於 0.5 左右 10/07 21:32
2F:推 mystea:可以把subroutine想成是C里的void function吗? 10/08 04:53
3F:→ sjgau:可以 10/08 08:41