level 1
Program Main
Implicit None
Integer :: N , M , Number , i , j , iloc , jloc
Integer , Allocatable :: Mat(:,:)
Write(*,"(A12\)")"Input Dim = "
Read(*,*)N
Allocate(Mat(N , N))
M = 2 * N + 1
Number = 1
Do i = 1 , M
If(mod(i , 2) == 1)Then
iloc = 1
jloc = i
Do j = 1 , i
If( iloc > 0 .and. iloc <= N .and. jloc > 0 .and. jloc <= N)Then
Mat(iloc , jloc) = Number
Number = Number + 1
End If
iloc = iloc + 1
jloc = jloc - 1
End Do
Else
iloc = i
jloc = 1
Do j = 1 , i
If( iloc > 0 .and. iloc <= N .and. jloc > 0 .and. jloc <= N)Then
Mat(iloc , jloc) = Number
Number = Number + 1
End If
iloc = iloc - 1
jloc = jloc + 1
End Do
End If
End Do
Do i = 1 , N
Write(*,"(18I6)")Mat(i,:)
End Do
Deallocate(Mat)
End Program
2018年05月29日 03点05分