精选问答
2010-5-22 产生80个10-99的随机数,求出素数的个数并求出所有素数的和 写VB代码

2019-04-13

2010-5-22 产生80个10-99的随机数,求出素数的个数并求出所有素数的和 写VB代码
优质解答
Dim a(80) As Integer, sum As Integer
Dim i!, j!, k!
Dim t As Boolean
Randomize
For i = 0 To 79
a(i) = Int(89 * Rnd + 10)
t = 1
For j = 2 To a(i) - 1
If a(i) Mod j = 0 Then t = 0
Next j
If t Then
sum = sum + a(i)
k = k + 1
Print a(i);
If k Mod 10 = 0 Then Print
End If
Next i
Print
Print "素数个数为:" & k
Print "和为:" & sum
Dim a(80) As Integer, sum As Integer
Dim i!, j!, k!
Dim t As Boolean
Randomize
For i = 0 To 79
a(i) = Int(89 * Rnd + 10)
t = 1
For j = 2 To a(i) - 1
If a(i) Mod j = 0 Then t = 0
Next j
If t Then
sum = sum + a(i)
k = k + 1
Print a(i);
If k Mod 10 = 0 Then Print
End If
Next i
Print
Print "素数个数为:" & k
Print "和为:" & sum
相关问答