2007年1月28日 星期日

很有用的兩個副程式,skip1(), pause1()

call skip1(3)
跳三行空白

call pause1
暫停 程式的執行,讓你有機會 仔細的觀察
程式的計算結果的輸出,中間值的觀察,

很有用處喔
同時,可以學習 副程式的寫作。



[pre]

! begin of main()
implicit none
integer i

! test skip(), pause

call skip1(3)
do i=1,20,1
call skip1(i)
print *, 'i= ', i, ', i*i= ', i*i, ', sqrt(i)= ', sqrt(float(i))
call pause1
end do

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

subroutine skip1(no)
implicit none
integer no, i

! limits no in 1 .. 20
if ((no >= 1) .AND. (no <= 20)) then
! no is OK!
do i=1, no
print *, ' '
end do
else
! no is invalid
print *, ' '
end if

end ! of sub. skip1()
! -----------------------------------------------

subroutine pause1
implicit none
integer no

print *, 'Input 0 for stop the program, others for continue: '
read(*, '(I2)')no

if (no .EQ. 0) then
stop
end if

end ! of sub. pause1()
! -----------------------------------------------


[/pre]

沒有留言: