vb 高手看看这个怎么写
1.将随机产生的80个整数存入数组,按每行10个数输出到窗体或文本框中。2.奇数也存入另一个数组,将排好序的奇数输出到窗体或文本框中。
3.用Sub子过程或Function函数过程判断随机整数是否为素数。
4.将素数按每行10个数在窗体或文本框中输出。
补充:有木有vb 高手 QQ加你也可以的
补充:有木有vb 高手 QQ加你也可以的
答案:Private Sub Command1_Click() '添加一个按钮和一个文本框,并将文本框的MultiLine 属性设为true
Dim a(1 To 80) As Integer, b() As Integer
Dim s
Dim s1 As String
Randomize
s1 = "产生的随机数为:" & vbCrLf
For i = 1 To 80
a(i) = Int(Rnd * 90 + 10)
If a(i) Mod 2 = 1 Then
m = m + 1
ReDim Preserve b(1 To m)
b(m) = a(i)
End If
s1 = s1 & Str(a(i))
If i Mod 10 = 0 Then s1 = s1 & vbCrLf
Next i
s1 = s1 & vbCrLf
s1 = s1 & "奇数为:" & vbCrLf
For i = 1 To UBound(b) - 1
For j = i To UBound(b)
If b(i) > b(j) Then d = b(i): b(i) = b(j): b(j) = d
Next j
Next i
For i = 1 To UBound(b)
s1 = s1 & Str(b(i))
If i Mod 10 = 0 Then s1 = s1 & vbCrLf
Next i
s1 = s1 & vbCrLf
s1 = s1 & "素数为:" & vbCrLf
n = 0
For i = 1 To 80
If ss(a(i)) Then
s1 = s1 & Str(a(i))
s = s + a(i)
n = n + 1
If n Mod 10 = 0 Then Print
End If
Next i
s1 = s1 & vbCrLf
s1 = s1 & vbCrLf & "素数的和为:" & s
Text1.Text = s1
End Sub
Function ss(p) As Boolean
If p = 1 Then Exit Function
For t = 2 To Sqr(p)
If p Mod t = 0 Then Exit Function
Next t
ss = True
End Function