VB编程题
【题目】编写程序,找出介于a和b之间所有能构成幻影素数的数。所谓幻影素数是指自身为素数,其反序数也是素数的数。例如107与701都是素数,所以107是幻影素数。【编程要求...
【题目】编写程序,找出介于a和b之间所有能构成幻影素数的数。所谓幻影素数是指自身为素数,其反序数也是素数的数。例如107与701都是素数,所以107是幻影素数。
【编程要求】
1. 程序参考界面如图所示,编程时不得增加和减少界面对象或改变对象的种类,窗体及界面元素大小适中,且均可见;
2. 运行程序,在文本框A和文本框B中输入指定数据范围,再按“运行”按钮,将找出的幻影素数存放在列表框中(若指定区间无幻影素数,则输出“本区间无幻影素数”)。按“清除”按钮,将文本框和列表框清空,焦点置于文本框A上;
3. 程序中应定义一个名为prime的函数过程,用于判断一个整数是否为素数;再定义一个求一个整数的反序数的通用过程。 展开
【编程要求】
1. 程序参考界面如图所示,编程时不得增加和减少界面对象或改变对象的种类,窗体及界面元素大小适中,且均可见;
2. 运行程序,在文本框A和文本框B中输入指定数据范围,再按“运行”按钮,将找出的幻影素数存放在列表框中(若指定区间无幻影素数,则输出“本区间无幻影素数”)。按“清除”按钮,将文本框和列表框清空,焦点置于文本框A上;
3. 程序中应定义一个名为prime的函数过程,用于判断一个整数是否为素数;再定义一个求一个整数的反序数的通用过程。 展开
2个回答
展开全部
将下面内容复制到记事本 另存为form1.frm文件
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3555
ClientLeft = 60
ClientTop = 450
ClientWidth = 6570
LinkTopic = "Form1"
ScaleHeight = 3555
ScaleWidth = 6570
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "清除"
Height = 495
Left = 4200
TabIndex = 4
Top = 1800
Width = 975
End
Begin VB.ListBox List1
Height = 1320
Left = 480
TabIndex = 3
Top = 1440
Width = 3255
End
Begin VB.CommandButton Command1
Caption = "运行"
Height = 495
Left = 4200
TabIndex = 2
Top = 600
Width = 1095
End
Begin VB.TextBox Text2
Height = 615
Left = 2280
TabIndex = 1
Top = 360
Width = 1335
End
Begin VB.TextBox Text1
Height = 615
Left = 480
TabIndex = 0
Top = 360
Width = 1455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
For i = Val(Text1.Text) To Val(Text2.Text)
Print dx(i)
If Prime(i) = True And Prime(CLng(dx(i))) = True Then List1.AddItem i
Next
End Sub
Private Function Prime(ByVal n As Long) As Boolean
For i = 2 To Int(Sqr(n))
If n Mod i = 0 Then
Prime = False
Exit Function
End If
Next i
Prime = True
End Function
Private Function dx(ByVal x As Integer) As String '求一个数的倒序
Dim i As Integer
For i = 1 To Len(CStr(x))
dx = Mid(CStr(x), i, 1) & dx
Next i
End Function
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
List1.Clear
Text1.SetFocus
End Sub
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3555
ClientLeft = 60
ClientTop = 450
ClientWidth = 6570
LinkTopic = "Form1"
ScaleHeight = 3555
ScaleWidth = 6570
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "清除"
Height = 495
Left = 4200
TabIndex = 4
Top = 1800
Width = 975
End
Begin VB.ListBox List1
Height = 1320
Left = 480
TabIndex = 3
Top = 1440
Width = 3255
End
Begin VB.CommandButton Command1
Caption = "运行"
Height = 495
Left = 4200
TabIndex = 2
Top = 600
Width = 1095
End
Begin VB.TextBox Text2
Height = 615
Left = 2280
TabIndex = 1
Top = 360
Width = 1335
End
Begin VB.TextBox Text1
Height = 615
Left = 480
TabIndex = 0
Top = 360
Width = 1455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
For i = Val(Text1.Text) To Val(Text2.Text)
Print dx(i)
If Prime(i) = True And Prime(CLng(dx(i))) = True Then List1.AddItem i
Next
End Sub
Private Function Prime(ByVal n As Long) As Boolean
For i = 2 To Int(Sqr(n))
If n Mod i = 0 Then
Prime = False
Exit Function
End If
Next i
Prime = True
End Function
Private Function dx(ByVal x As Integer) As String '求一个数的倒序
Dim i As Integer
For i = 1 To Len(CStr(x))
dx = Mid(CStr(x), i, 1) & dx
Next i
End Function
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
List1.Clear
Text1.SetFocus
End Sub
展开全部
啊`同样的问题``不知道是不是一个人的`我这里就把我刚回答
的给贴出来了
我用vb6写的一个`不是.net
你仿照这个写一个吧
dim
u
,
r
as
boolean
'
u为true时picturebox向下滚,
u为
false时向上``
同理对于r =
true
向左`r=false向右
'
以上为
全局变量
private
sub
timer1_timer()
'interval=1
if
picture1.top
<=
0
then
u
=
false
if
picture1.top
>=
me.scaleheight
-
picture1.height
then
u
=
true
if
picture1.left
<=
0
then
r
=
false
if
picture1.left
>=
me.width
-
picture1.width
then
r
=
true
if
r
=
false
then
picture1.left
=
picture1.left
+
50
else
picture1.left
=
picture1.left
-
50
end
if
if
u
=
false
then
picture1.top
=
picture1.top
+
50
else
picture1.top
=
picture1.top
-
50
end
if
end
sub
的给贴出来了
我用vb6写的一个`不是.net
你仿照这个写一个吧
dim
u
,
r
as
boolean
'
u为true时picturebox向下滚,
u为
false时向上``
同理对于r =
true
向左`r=false向右
'
以上为
全局变量
private
sub
timer1_timer()
'interval=1
if
picture1.top
<=
0
then
u
=
false
if
picture1.top
>=
me.scaleheight
-
picture1.height
then
u
=
true
if
picture1.left
<=
0
then
r
=
false
if
picture1.left
>=
me.width
-
picture1.width
then
r
=
true
if
r
=
false
then
picture1.left
=
picture1.left
+
50
else
picture1.left
=
picture1.left
-
50
end
if
if
u
=
false
then
picture1.top
=
picture1.top
+
50
else
picture1.top
=
picture1.top
-
50
end
if
end
sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询