?? ex0825.f90
字號:
program ex0825
implicit none
interface ! 定義函數(shù)func的接口
function random10(lbound, ubound)
implicit none
real :: lbound, ubound
real :: random10(10) ! 傳回值是個(gè)數(shù)組
end function
end interface
real :: a(10)
CALL RANDOM_SEED() ! 庫函數(shù)子程式, 使用隨機(jī)數(shù)前調(diào)用
a = random10(1.0, 10.0)! 產(chǎn)生10個(gè)1.0~1.0之間的隨機(jī)數(shù)
write(*,"(10F6.2)") a ! 輸出數(shù)組a的內(nèi)容
end
! random10會(huì)返回10個(gè)范圍在lbound到ubound之間的隨機(jī)數(shù)
function random10(lbound, ubound)
implicit none
real :: lbound, ubound
real :: len
real :: random10(10)
real t
integer i
len = ubound - lbound ! 計(jì)算范圍大小
do i=1,10
call random_number(t) ! t會(huì)是0~1之間的隨機(jī)數(shù)
random10(i) = lbound + len * t ! 把t轉(zhuǎn)換成lbound~ubound間的隨機(jī)數(shù)
end do
return
end
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -