求高手用vb编写歌德巴赫猜想!

来源:百度知道 编辑:UC知道 时间:2024/06/03 16:42:01

Option Explicit

Private Sub Command1_Click()
Dim s!, x%, i%, y%, j%
Dim f1 As Boolean, f2 As Boolean
Do
s = InputBox("s=")
If s < 6 Or s <> Int(s) Or s Mod 2 = 0 Then MsgBox "你输入的数据不符合要求!请重新输入!"
Loop Until s >= 6 And s = Int(s) And s Mod 2 = 0
For x = 3 To s / 2 Step 2 '第一个数X的素数判断过程
f1 = True
For i = 2 To Sqr(x)
If x Mod i = 0 Then f1 = False: Exit For
Next i
'第二个数Y的素数判断过程,也可以加条件!
y = s - x
f2 = True
For j = 2 To Sqr(y)
If y Mod j = 0 Then f2 = False: Exit For
Next j
If f1 And f2 Then Print s; "="; x; "+"; y
Next x
End Sub