我将你的代码改了一下,你看看这里面的一些代码习惯。会比你自己的代码可读性、可修改性好一些。(例如要改成6*6的就更容易)
[Fortran] 纯文本查看 复制代码 Program main
Implicit None !// 很重要
Real w(5, 5) , x1 , x2
Call readin(w)
Call putout(w)
Call wmax(w, x1, x2)
Write (*, *) 'X1=', x1, 'X2=', x2
contains
Subroutine readin(a)
Implicit None !// 很重要
Real a(:,:)
integer :: i
Write (*, *) 'Enter 5*5 matrix:'
Do i = 1, size(a,dim=1)
Read (*, *) a(i,:)
End Do
End Subroutine readin
Subroutine putout(a)
Implicit None !// 很重要
Real a(:, :)
integer :: i
Do i = 1, size(a,dim=1)
Write (*, *) a(i,:)
End Do
End Subroutine putout
Subroutine wmax(a, s1, s2)
Implicit None !// 很重要
Real a(:, :) , s1 , s2
integer :: i , N
N = size(a,dim=2)
s1 = a(1, 1)
s2 = a(1, N)
Do i = 2, N
If (s1<a(i,i)) s1 = a(i, i)
If (s2<a(i,N-i+1)) s2 = a(i, N-i+1)
End Do
End Subroutine wmax
End Program main |