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
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 02:16:16
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
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 < n - 1 Then
f = True
Print r;
End If
End Function
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
Public Function IsPrime(ByVal x As Integer) As Boolean
Dim i As Integer
IsPrime = True
For i=2 To x-1
If (x Mod i) = 0 Then
IsPrime = False
Exit Function
End If
Next
End Function
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)
If IsPrime(r) Then s = s + r
Next
Print r
End Sub