
2个回答
2013-06-06
展开全部
放置一个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
'已经运行过.
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
'已经运行过.
2013-06-06
展开全部
这是我修改了好多次才定稿的~~个人以为,简直可谓——完美O(∩_∩)O~#include<stdio.h>
int fun(int a);
void main()
{
int t,i,p=1;
printf("input a num:");
scanf("%d",&t);
while(t<=6||t%2!=0)
{
printf("data error!\nreenter a num which is bigger than 6 and is the times of 2:");
scanf("%d",&t);
}
for(i=3;i<=t/2;i++)
if(fun(i)&&fun(t-i))
{
printf("(%d) %d=%d+%d\n",p,t,i,t-i);
p++;
}
}
int fun(int a)
{
int n;
for(n=2;n<a/2;n++)
if(a%n==0)
return 0;
return 1;
}
int fun(int a);
void main()
{
int t,i,p=1;
printf("input a num:");
scanf("%d",&t);
while(t<=6||t%2!=0)
{
printf("data error!\nreenter a num which is bigger than 6 and is the times of 2:");
scanf("%d",&t);
}
for(i=3;i<=t/2;i++)
if(fun(i)&&fun(t-i))
{
printf("(%d) %d=%d+%d\n",p,t,i,t-i);
p++;
}
}
int fun(int a)
{
int n;
for(n=2;n<a/2;n++)
if(a%n==0)
return 0;
return 1;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询