修改後的程式如下:
program homework2
implicit none
real t(20,20)
integer i,j,k
i=1
do j=2,19
t(i,j)=0
end do
i=20
do j=2,19
t(i,j)=0
end do
j=1
do i=1,20
t(i,j)=0
end do
j=20
do i=1,20
t(i,j)=1
! 如果你希望外圈都是 0, 這行應該是 t(i,j)=0
end do
outter: do i=2,19
inner: do j=2, 19
t(i,j)=1
end do inner
end do outter
do k=1,50
outter2: do i=2, 19
inner2: do j=2, 19
t(i,j)=(t(i+1,j)+t(i-1,j)+t(i,j+1)+t(i,j-1))/4
end do inner2
end do outter2
end do
open(unit=15, file='hw2_data.txt') ! open 指令應該移到 do 迴圈外
do i=1, 20
write(15,*) (t(i,j), j=1, 20) ! 每列各印出 20 個數字
end do
close(15)
stop
end
用「記事本」看 hw2_data.txt 時,格式不要「自動換行」較清楚。
還有,前 4 個 do 迴圈可合併如下較精簡:
do i=1,20,19
do j=1,20
t(i,j)=0
t(j,i)=0
end do
end do
This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers. FiveFilters.org recommends: March Against Mainstream Media (More info).
留言列表