【加试题】完善如下功能的Visual Basic程序:在文本框Text1中输入一个偶数,单击“求解”按钮Command1,将这个偶数拆分成二个素数之和。请完成下面两个小题。程序代码如下:
Private Sub Command1_Click()
Dim n As Integer, i As Integer
List1.Clear
n = Val(Text1.Text)
If n Mod 2 = 0 Then
For i = 2 To Int(n / 2)
If isodd(i) = (isodd(n - i)) Then
List1.AddItem Str(n) + " =" + Str(i) + " +" + Str(n - i)
End If
Next i
Else
Text1.Text = Str(n) + "不是偶数!"
End If
End Sub
Private Function isodd(n As Integer) as boolean
Dim f As integer
f = 0
For i = 2 To Sqr(n)
If n Mod i = 0 Then f = 1: Exit For
Next i
isodd = f
End Function