以下是 函數的 範例,
Fortran 並沒有提供 所有的數學函數功能,
以下示範 degree 轉 radian 的函數寫作
[code]
! begin of main()
implicit none
real x, y
real dtor ! is a function
! sin(60)= sqrt(3)/2
! sin(45)= 1/sqrt(2)
x= 60.0
y= sin(dtor(x))
print *, 'x= ', x, ', y= ', y
y= sqrt(3.0)/2.0
print *, 'x= ', x, ', y + 1= ', y + 1
pause
! -----------------------------------------------
x= 45.0
y= sin(dtor(x))
print *, 'x= ', x, ', y= ', y
y= 1.0/sqrt(2.0)
print *, 'x= ', x, ', y + 1= ', y + 1
end
! -----------------------------------------------
! y= sin(dtor(x))
real function dtor(x)
implicit none
real x
dtor= x/180.0*(4.0*atan(1.0))
end
[/code]
沒有留言:
張貼留言