vb随机产生10个两位数随机正整数,求其中素数之和(用过程实现判断一个数是否是素数)Private Sub Command1_Click()Dim a As Integer, r As Integer, s As Integers = 0For a = 1 To 10r = Int(90 * Rnd + 10)Print r;If f = True Then s = s + rNext aPrintPrint "其中素数的总和="; sEnd SubPublic Function su(i As Integer, n As Integer) As BooleanDim f As BooleanFor i = 2 To n - 1If n Mod i = 0 Thenf = FalseExit ForEnd IfNext iIf i f = TruePrint r;End IfEnd Function
问题描述:
vb随机产生10个两位数随机正整数,求其中素数之和(用过程实现判断一个数是否是素数)
Private Sub Command1_Click()
Dim a As Integer, r As Integer, s As Integer
s = 0
For a = 1 To 10
r = Int(90 * Rnd + 10)
Print r;
If f = True Then s = s + r
Next a
Print
Print "其中素数的总和="; s
End Sub
Public Function su(i As Integer, n As Integer) As Boolean
Dim f As Boolean
For i = 2 To n - 1
If n Mod i = 0 Then
f = False
Exit For
End If
Next i
If i f = True
Print r;
End If
End Function
答