发布网友 发布时间:2022-04-25 00:03
共1个回答
热心网友 时间:2023-10-16 13:53
Option Explicit
Function fc(a) As Boolean
Dim i As Long
For i = 2 To Int(a / 2)
If a Mod i = 0 Then
fc = False
Exit For
Else
fc = True
End If
Next i
End Function
Private Sub Form_Click()
Dim i, j, k, m, s, g, f As Integer
j = 0
k = 0
f = 0
Dim a(1 To 80) As Integer
Dim b(1 To 80) As Integer
Dim c(1 To 80) As Integer
Dim d(1 To 80) As Integer
For i = 1 To 80
a(i) = Int(Rnd() * 100)
if a(i)<10 then a(i)=a(i)+10
If a(i) Mod 2 = 0 Then
j = j + 1
b(j) = a(i)
Else
k = k + 1
c(k) = a(i)
End If
Next i
For i = 1 To j
For m = i + 1 To j
If b(i) < b(m) Then
s = b(m)
b(m) = b(i)
b(i) = s
End If
Next m
Next i
For i = 1 To k
For m = i + 1 To k
If b(i) < b(m) Then
s = c(m)
c(m) = c(i)
c(i) = s
End If
Next m
Next i
For i = 1 To 80
If fc(a(i)) = True Then
g = g + 1
d(g) = a(i)
End If
Next i
Print "随机数:"
For i = 1 To 80
f = f + 1
If f < 11 Then
Print " " & a(i);
Else
f = 1
Print
Print " " & a(i);
End If
Next i
Print
Print "偶数:"
f = 0
For i = 1 To j
f = f + 1
If f < 11 Then
Print " " & b(i);
Else
f = 1
Print
Print " " & b(i);
End If
Next i
Print
Print "奇数:"
f = 0
For i = 1 To k
f = f + 1
If f < 11 Then
Print " " & c(i);
Else
f = 1
Print
Print " " & c(i);
End If
Next i
Print
Print "素数:"
f = 0
For i = 1 To g
f = f + 1
If f < 11 Then
Print " " & d(i);
Else
f = 1
Print
Print " " & d(i);
End If
Next i
s = 0
Print
Print "素数个数:" & g
For i = 1 To g
s = s + d(i)
Next i
Print "素数总和:" & s
End Sub