(急急急急急!!!)vb问题求助

来源:百度知道 编辑:UC知道 时间:2024/05/31 10:17:23
编写程序,当程序运行时,在文本框内输入一个正整数,找出大于该数据的最小的3个素数,在有3个标签的标签控件数组中输出。(例如输入30,则找出的3个素数为31、37和41)
急急急急急!!!)急急急急急!!!)急急急急急!!!)急急急急急!!!)急急急急急!!!)急急急急急!!!)急急急急急!!!)急急急急急!!!)谢谢大家了

由于个数较少
可以用比较笨的办法
n为输入的数

m=0
do
bool=true
n=n+1
for i=2 to sqr(n)
if n mod i =0 then bool=false:exit for
next
if bool then 输出一个质数:m=m+1:if m=3 then exit do
loop

输入框为:text1.text
三个label为:label1,label2,label3

Dim iDat As Integer
Dim iCT As Integer
Dim lLoop As Long
Dim lb(1 To 3) As Label
Dim bIsOK As Boolean

Set lb(1) = Label1
Set lb(2) = Label2
Set lb(3) = Label3

iDat = CInt(Text1.Text)
iCT = 0
While iCT < 3
iDat = iDat + 1
bIsOK = True
For lLoop = 2 To Int(Sqr(iDat))
If iDat Mod lLoop = 0 Then
bIsOK = False
Exit For
End If

Next
If bIsOK Then
iCT = iCT + 1
lb(iCT).Caption = CStr(iDat)
End If
Wend