vb编程问题,求求各位大神,随机产生一个m行n列的二维数组,编写一个 20
vb编程问题,求求各位大神,随机产生一个m行n列的二维数组,编写一个有排序功能的sub,将二维数组的每行排序后输出,再编写一个判断质数的函数,将数组里所有的质数输出。...
vb编程问题,求求各位大神,随机产生一个m行n列的二维数组,编写一个有排序功能的sub,将二维数组的每行排序后输出,再编写一个判断质数的函数,将数组里所有的质数输出。
展开
1个回答
展开全部
Private Sub Command1_Click()
Cls
Randomize (Timer)
Dim m As Integer, n As Integer
Dim a() As Integer
m = InputBox("m=", "", 5)
n = InputBox("n=", "", 10)
ReDim a(1 To m, 1 To n)
For i = 1 To m
For j = 1 To n
a(i, j) = Int(Rnd * 900 + 100)
Next j
Next i
Call PrintArray(a, m, n)
Call Sort(a, m, n)
Call PrintArray(a, m, n)
For i = 1 To m
For j = 1 To n
If IsFrimeNumber(a(i, j)) Then
c = c + 1
Print a(i, j);
If c Mod 10 = 0 Then Print
End If
Next j
Next i
End Sub
Private Sub Sort(ByRef a() As Integer, ByVal m As Integer, ByVal n As Integer)
For i = 1 To m
For j = 1 To n - 1
For k = j + 1 To n
If a(i, k) < a(i, j) Then
t = a(i, j)
a(i, j) = a(i, k)
a(i, k) = t
End If
Next k
Next j
Next i
End Sub
Private Sub PrintArray(ByRef a() As Integer, ByVal m As Integer, ByVal n As Integer)
For i = 1 To m
For j = 1 To n
Print a(i, j);
Next j
Next i
End Sub
Private Function IsFrimeNumber(ByVal n As Integer) As Boolean
IsFrimeNumber = True
For i = 2 To Sqr(n)
If n Mod i = 0 Then
IsFrimeNumber = False
Exit Function
End If
Next i
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询