2007年1月28日 星期日

主程式,副程式分離以後的 費氏數列

CODE {
display: block; /* fixes a strange ie margin bug */
font-family: Courier New;
font-size: 8pt;
overflow:auto;
background: #f0f0f0 url(http://klcintw.images.googlepages.com/Code_BG.gif) lef\
t top repeat-y;
border: 1px solid #ccc;
padding: 10px 10px 10px 21px;
max-height:200px;
line-height: 1.2em;
}


請注意 include 這個指令,
三個副程式,已經移到另外的一個檔案,
file: sj-01.inc

如此,我們可以化整為零,各個擊破


[code]

! file: VF26.F90
include 'sj-01.inc'
! -----------------------------------------------

! begin of main()
implicit none

integer no, f1, f2
real r1, r2
integer fs !for function 費氏數列

r2= (1.0 + sqrt(5.0))/2.0
call skip1(3)
print *, 'r2= ', r2
print *, '費氏數列的前後兩項的比值 會趨近於 黃金分割'
! -----------------------------------------------

! 以費氏數列 示範遞迴程式的寫作
call skip1(3)
do no=1, 18, 1
f1= fs(no+1)
f2= fs(no)
r1= float(f1)/float(f2)

print *, 'no= ', no, 'f1= ', f1, ', f2= ', f2, ', r1= ', r1
if ((mod(no, 10)) .EQ. 0) then
call skip1(1)
call pause1
end if
end do

end ! of main()
! -----------------------------------------------
! end of file


[/code]

沒有留言: