答案:主要算法我已经帮你写好了,你觉得不好的话可以自己稍微改动Option Explicit
Private Sub Command1_Click()Dim i, j, k, m, n, temp, q As IntegerDim a() As Integer
q = Val(InputBox("输入奇数"))ReDim a(q, q)
i = 0j = (q - 1) / 2a(i, j) = 1 For temp = 2 To q * qIf i = 0 And j = q - 1 Then i = 1Else m = i n = j i = i - 1 j = j + 1 If i < 0 Then i = q - 1 If (j > q - 1) Then j = 0
If a(i, j) <> 0 Then i = m + 1 j = n
End IfEnd If a(i, j) = temp Next For i = 0 To q - 1 For j = 0 To q - 1 Text1.Text = Text1.Text & a(i, j) & " " Next Text1.Text = Text1.Text & vbCrLf Next End Sub
上一个:VB编程问题
下一个:VB编程代码