کد:
Integer , Dimension (:,:), Allocatable :: Mat
Integer N
Integer Maximum
Print*, "Please Enter N (Matrix is N*N):"
Read*, N
Allocate (Mat (N,N))
Print*, "Please Enter Matrix Elements (Mat (1,1), Mat(1,2), ...):"
Do I = 1, N
Do J = 1, N
Read*, Mat (I,J)
End Do
End Do
Do I = 1, N
Do J = 1, N
If (I > 1 .And. I < N .And. J > 1 .And. J < N) Then
Maximum = Max (Mat(I-1,J), Mat(I+1,J), Mat(I,J-1), Mat(I,J+1), &
Mat(I-1,J+1), Mat(I+1,J-1), Mat(I+1,J+1), Mat(I-1,J-1))
Print*, Maximum
End If
End Do
End Do
End