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/11/28 03:05:34
- h78`c:Vv( E,I2%8FR:X
0$U84zTyhB ή$Đae$h
x!LaJm.¶ftבiτ Y8%GT ј2/&&S&dq##O930N^QOc$;Od.5U&:sjKѠ4m3Q18Q`$Rڑ(rNxE/[:+f
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