用VB验证哥德巴赫猜想,任何一个大于6的偶数,均表示为两个素数之和,要求从键盘输入一个大于6的偶数,打印出分解的结果.
2019-05-28
用VB验证哥德巴赫猜想,任何一个大于6的偶数,均表示为两个素数之和,
要求从键盘输入一个大于6的偶数,打印出分解的结果.
优质解答
Dim i,j,n As Integer,flag As Boolean
Private Sub Command1_Click()
n = Text1.Text
For i = 2 To n / 2
flag = False
For j = 2 To Sqr(i)
If i Mod j = 0 Then
flag = True
End If
Next j
For j = 2 To Sqr(n - i)
If i Mod j = 0 Then
flag = True
End If
Next j
If flag = False Then
Text1.Text = n & "=" & i & "+" & n - i
Exit For
End If
Next i
End Sub
Dim i,j,n As Integer,flag As Boolean
Private Sub Command1_Click()
n = Text1.Text
For i = 2 To n / 2
flag = False
For j = 2 To Sqr(i)
If i Mod j = 0 Then
flag = True
End If
Next j
For j = 2 To Sqr(n - i)
If i Mod j = 0 Then
flag = True
End If
Next j
If flag = False Then
Text1.Text = n & "=" & i & "+" & n - i
Exit For
End If
Next i
End Sub