...利用随机函数产生80个10~99之间的随机整数,将其中的偶数按由小...

发布网友 发布时间:2024-10-23 22:33

我来回答

2个回答

热心网友 时间:2024-11-16 14:08

Next k
If f = True Then
Print m;
End If
这里修

Dim j
If f = True Then
j=j+1;
if(j%10 == 0) Then
Print 回车(我也不知道vb的回车怎么输出,你自己加上去看看吧)
End If
Print m;
End If
Print j;

热心网友 时间:2024-11-16 14:09

Dim a%(1 to 80), i%, k%, t%, b%(1 to 80), c%(1 to 80)
Private Sub Command1_Click()
Me.Cls
Dim j As Integer
Randomize
t = 1
k = 1
For i = 1 To 80
a(i) = Int(Rnd * 90) + 10

If a(i) Mod 2 = 1 Then
b(k) = a(i)
k = k + 1
End If

If IsPrimeNum(a(i)) Then
c(t) = a(i)
t = t + 1
End If
Next i

Print "全部"

For i = 1 To 80
Print a(i);
If i Mod 10 = 0 Then Print
Next i

SortArray b, k - 1

Print "奇数"

For i = 1 To k - 1
Print b(i);
If i Mod 10 = 0 Then Print
Next i

Print

SortArray c, t - 1

Print "素数"

For i = 1 To t - 1
Print c(i);
If i Mod 10 = 0 Then Print
Next i
End Sub

Private Function IsPrimeNum(V As Integer) As Boolean
Dim i As Integer
Dim flag As Boolean
flag = True
For i = 2 To V - 1
If V Mod i = 0 Then
flag = False
Exit For
End If
Next i
IsPrimeNum = flag

End Function

Private Sub SortArray(arr() As Integer, ByVal size As Integer)
Dim i As Integer
Dim j As Integer
Dim t As Integer
For i = 1 To size
For j = i + 1 To size
If arr(i) > arr(j) Then t = arr(i): arr(i) = arr(j): arr(j) = t
Next j
Next i

End Sub
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com