VB输入任意一个正整数,若该数不是一个素数,则找出一个大于它的最小素数Dim n As Integer,i As IntegerDim flg As Booleann = Text1n = n + 1For i = 2 To Sqr(n)If n Mod i = 0 Then Exit ForNext iIf i > Sqr(n) Then flg = TrueIf flg
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 11:41:12
VB输入任意一个正整数,若该数不是一个素数,则找出一个大于它的最小素数Dim n As Integer,i As IntegerDim flg As Booleann = Text1n = n + 1For i = 2 To Sqr(n)If n Mod i = 0 Then Exit ForNext iIf i > Sqr(n) Then flg = TrueIf flg
VB输入任意一个正整数,若该数不是一个素数,则找出一个大于它的最小素数
Dim n As Integer,i As Integer
Dim flg As Boolean
n = Text1
n = n + 1
For i = 2 To Sqr(n)
If n Mod i = 0 Then Exit For
Next i
If i > Sqr(n) Then flg = True
If flg = True Then
Text2.Text = CStr(n) & "是素数"
Else
Do
n = n + 1
For i = 2 To Sqr(n)
If n Mod i = 0 Then Exit For
Next i
If i > Sqr(n) Then flg = True
Loop Until flg = True
Label2.Caption = "大于" & Text1.Text & "的最小素数是"
Text2.Text = CStr(n)
请问这段代码错在哪里啊
VB输入任意一个正整数,若该数不是一个素数,则找出一个大于它的最小素数Dim n As Integer,i As IntegerDim flg As Booleann = Text1n = n + 1For i = 2 To Sqr(n)If n Mod i = 0 Then Exit ForNext iIf i > Sqr(n) Then flg = TrueIf flg
Dim n As Integer, i As Integer
Dim flg As Boolean
n = Val(Text1.Text)
n = n + 1
For i = 2 To Sqr(n)
If n Mod i = 0 Then Exit For
Next i
If i > Sqr(n) Then flg = True
If flg = True Then
Text2.Text = CStr(n) & "是素数"
Else
Do
n = n + 1
For i = 2 To Sqr(n)
If n Mod i = 0 Then Exit For
Next i
If i > Sqr(n) Then flg = True
Loop Until flg = True
Label2.Caption = "大于" & Text1.Text & "的最小素数是"
Text2.Text = CStr(n)
End If