因为代码不全,所以基本上看不出来要做什么,我有照着这个题目要求做的完整代码,贴在下面,你可以看看:
以下代码不需要任何控件
Private Sub Form_Activate()
Dim a(1 To 100) As Integer, prime(1 To 100) As Integer, np As Integer, sp As Integer
'a数组存放100个随机整数,prime数组存放素数,np存放素数个数,sp存放素数总和
Randomize
np = 0
sp = 0
Print "100个随机整数为"
For i = 1 To 100
a(i) = 10 + Int(90 * Rnd)
Print a(i);
If i Mod 10 = 0 Then Print
If isprime(a(i)) Then
np = np + 1
prime(np) = a(i)
sp = sp + a(i)
End If
Next
Print
Print "包含的素数依次为"
For i = 1 To np
Print prime(i);
If i Mod 10 = 0 Then Print
Next
Print
Print "素数个数为"; np; ",素数总和为"; sp
End Sub
Function isprime(ByVal Num As Integer) As Boolean '判断是否为素数的函数
If Num < 2 Then isprime = False: Exit Function
Dim i As Integer
For i = 2 To Sqr(Num)
If (Num Mod i) = 0 Then
isprime = False
Exit Function
End If
Next i
isprime = True
End Function
你的程序 不完整
不过,t As Single,能作为 下标?
下标 一般是 整数
判断素数 的例程很多,你随便搜索 吧
Good luck