求VB代码 用数组a(i) 随机产生30个正整数,并以每行10个输出,然后再次输出其中的素数
展开全部
Function prime(x)
If x <= 3 Then prime = True: Exit Function
For i = 2 To Sqr(x)
If x Mod i = 0 Then prime = False: Exit Function
Next i
prime = True
End Function
Private Sub form_click()
Dim a(1 To 30)
Randomize
Print "30个随机历辩模数是:"
For i = 1 To 30
a(i) = Int(Rnd * 90 + 10)
Print Right(" 灶核 " & a(i), 4);
肢缓If i Mod 10 = 0 Then Print
Next i
Print "其中是素数的有"
total = 0
For i = 1 To 30
If prime(a(i)) Then
Print Right(" " & a(i), 4);
total = total + 1
If total Mod 10 = 0 Then Print
End If
Next i
End Sub
追问
非常感谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询