在线等~~帮我修改一个vb程序啊,就是求一下和,谢谢,很简单的!!!

来源:百度知道 编辑:UC知道 时间:2024/05/06 02:52:50
Private Sub Form_click()
Cls
Dim a(100) As Integer, x As Integer
For I = 1 To 100
a(I) = Int(Rnd * 90) + 10
Print a(I);
If I Mod 10 = 0 Then Print
Next
Print
For I = 1 To 100
If Pd(a(I)) = True Then
Print a(I);
x = x + 1
If x Mod 10 = 0 Then Print
End If
Next
End Sub
Private Function Pd(ByVal n As Integer) As Boolean
Dim I As Integer
For I = 2 To n - 1
If n Mod I = 0 Then Exit For
Next I
If I >= n Then
Pd = True
Else
Pd = False
End If
End Function

这个没有求和的,就是帮我添加一段求和的

只是帮我做一下* 4 *就好了,谢谢

1.将随机产生的100个整数存入数组,按每行10个数输出到窗体或文本框中。
2. 用Sub子过程或Function函数过程判断随机整数是否为素数。
3. 将素数按每行10个数在窗体或文本框中输出。

4. 将素数的个数以及求和结果出到窗体或文本框中。

Private Sub Form_click()
Cls
Dim sum As Integer
Dim n As Integer
Dim a(100) As Integer, x As Integer
For I = 1 To 100
a(I) = Int(Rnd * 90) + 10
Print a(I);
If I Mod 10 = 0 Then Print
Next
Print
For I = 1 To 100
If Pd(a(I)) = True Then
sum = sum + a(I)
n = n + 1
Print a(I);
x = x + 1
If x Mod 10 = 0 Then Print
End If
Next
Print
Print "素数的和为:" & sum
Print "共有" & n & "个"
End Sub
Private Function Pd(ByVal n As Integer) As Boolean
Dim I As Integer
For I = 2 To n - 1
If n Mod I = 0 Then Exit For
Next I
If I >= n Then
Pd = True
Else
Pd = False
End If
End Function