编写一个验证哥德巴赫猜想的VB程序:程序运行时,在文本框Text1中输入一个大于等于4的偶数,单击“验证”按钮Command1后,如果哥德巴赫猜想验证成功,则在文本框Text2中显示“Yes”,并在列表框List1中显示用两个素数表示该偶数的等式,否则显示“No”。程序运行结果如图所示。
实现上述功能的VB代码如下,但加框处代码有错,请改正。
′函数pp(x)的功能是判断整数x是否为素数,若是素数则返回True,否则返回False
Function pp(x As Integer) As Boolean
Dim j As Integer
pp = True
j = 2
Do While j <= Int(Sqr(x)) And pp=True
If x Mod j = 0 Then pp = False Else
'①
Loop
End Function
Private Sub Command1_Click()
Dim n As Integer, p As Integer, q As Integer, pd As Boolean
n = Val(Text1.Text)
p = 1
pd = False
Do While Not pd And p < n
p = p + 1
'②
If pp(p) And pp(q) Then
Text2.Text = “Yes”
pd = True
List1.AddItem Str(n) + “=” + Str(p) + “+” + Str(q)
End If
Loop
If pd = False Then Text2.Text = “No”
End Sub
程序中加框①处应改正为;
加框②处应改正为。