编写VB程序验证歌德巴赫猜想:一个大于等于6的偶数可以表示为两个素数之和.
编写VB程序验证歌德巴赫猜想:一个大于等于6的偶数可以表示为两个素数之和.
编写VB程序验证歌德巴赫猜想:一个大于等于6的偶数可以表示为两个素数之和.
编写VB程序验证歌德巴赫猜想:一个大于等于6的偶数可以表示为两个素数之和.
放置一个command1,一个text1,不用再做其它设定,程序会自行设定各个参数,代码如下:
PrivateSubCommand1_Click()
DimNAsLong,IAsLong,JAsLong
IfIsNumeric(Text1.Text)Then
N=CLng(Text1.Text)
IfNMod2=0AndN>=6Then
ForI=2ToN2
IfI=2OrPd(I)Then
J=N-I
IfPd(J)Then
Label1.Caption="结果:"&N&"="&I&"+"&J&"符合!"
ExitSub
EndIf
EndIf
Next
Label1.Caption="结果:不符合!"
Else
Text1.Text="请输入大于或等于6的偶数!"
EndIf
Else
Text1.Text="请输入数字!"
EndIf
EndSub
PrivateSubForm_Click()
Cls
Print"双击退出"
Text1.Visible=True
Label1.Visible=True
Command1.Visible=True
EndSub
PrivateSubForm_DblClick()
End
EndSub
PrivateSubForm_Load()
Form1.Caption="哥德巴赫猜想"
Form1.Width=5000
Form1.Height=5000
Form1.Show
Form1.AutoRedraw=True
Text1.Text="在此输入一个大于等于6的偶数"
Text1.ForeColor=&H808080
Text1.Top=500
Text1.Left=200
Text1.Width=3000
Text1.Height=300
Text1.Visible=False
Label1.Caption=""
Label1.Top=1000
Label1.Left=200
Label1.Width=3000
Label1.Height=300
Label1.Visible=False
Command1.Caption="验证"
Command1.Top=2000
Command1.Left=200
Command1.Width=800
Command1.Height=300
Command1.Visible=False
Print"1942年德国数学家哥德巴赫给数学家欧拉的一封信中,"
Print"提出了把一个整数表示成两个素数之和的推测,"
Print"即一个充分大的偶数(大于等于6),"
Print"总可以分解为两个素数之和,"
Print"编写VisualBasic程序来验证这一猜想"
Print"单击开始."
EndSub
PrivateSubText1_GotFocus()
Text1.Text=""
Text1.ForeColor=&H0
Command1.Visible=True
EndSub
FunctionPd(aAsLong)AsBoolean
DimbAsLong
Forb=2Toa-1
DoEvents
IfaModb=0Then
Pd=False
ExitFor
Else
Pd=True
EndIf
Next
EndFunction
'已经运行过.