当前位置: > 编写VB程序验证歌德巴赫猜想:一个大于等于6的偶数可以表示为两个素数之和....
题目
编写VB程序验证歌德巴赫猜想:一个大于等于6的偶数可以表示为两个素数之和.

提问时间:2020-11-02

答案
放置一个command1,一个text1,不用再做其它设定,程序会自行设定各个参数,代码如下:
Private Sub Command1_Click()
Dim N As Long, I As Long, J As Long
If IsNumeric(Text1.Text) Then
N = CLng(Text1.Text)
If N Mod 2 = 0 And N >= 6 Then
For I = 2 To N \ 2
If I = 2 Or Pd(I) Then
J = N - I
If Pd(J) Then
Label1.Caption = "结果: " & N & "=" & I & "+" & J & "符合!"
Exit Sub
End If
End If
Next
Label1.Caption = "结果: 不符合!"
Else
Text1.Text = "请输入大于或等于6的偶数!"
End If
Else
Text1.Text = "请输入数字!"
End If
End Sub
Private Sub Form_Click()
Cls
Print "双击退出"
Text1.Visible = True
Label1.Visible = True
Command1.Visible = True
End Sub
Private Sub Form_DblClick()
End
End Sub
Private Sub Form_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 "编写Visual Basic程序来验证这一猜想"
Print "单击开始."
End Sub
Private Sub Text1_GotFocus()
Text1.Text = ""
Text1.ForeColor = &H0
Command1.Visible = True
End Sub
Function Pd(a As Long) As Boolean
Dim b As Long
For b = 2 To a - 1
DoEvents
If a Mod b = 0 Then
Pd = False
Exit For
Else
Pd = True
End If
Next
End Function
'已经运行过.
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.