哥德巴赫1742年给欧拉的信中哥德巴赫提出了以下猜想:任一大于2的偶数都可写成两个质数之和。下列程序的功能即验证哥德巴赫猜想。程序运行时,在文本框Text1中输入一个大于2的偶数,单击“证明”按钮Command1后,在列表框List1中输出所有符合猜想的组合,在标签Label2中输出共有多少个组合。程序运行效果如下图所示。
为实现上述功能程序如下,但加框处的代码有误,请改正。
Private Sub Command1_Click()
Dim n As Integer
Dim i As Integer, c As Integer
n = Val(Text1.Text)
List1.Clear
c = 0
If n Mod 2 = 0 Then
For
①
If
Then ②
List1.AddItem n & "=" & i & "+" & n - i
c = c + 1
End If
Next i
Label2.Caption = "共有" & c & "种组合"
Else
Label2.Caption = "请输入一个大于 2 的偶数"
End If
End Sub
Function is Prime(x As Integer) As Boolean
Dim i As Integer
Is Prime = True
For i = 2 To Int(Sqr(x))
If x Mod i = 0 Then
Is Prime = False
Exit For
End If
Next i
End Function
①{#blank#}1{#/blank#} ②{#blank#}2{#/blank#}