图1
图2
程序代码如下:
Private Sub Command1_Click()
Dim i As Integer
List1.Clear '清除列表框内容
For i = 3 To 97 ___①___ If f(i) And ② Then List1.AddItem Str(i) + " 和 " + Str(i + 2) End If Next i |
End Sub
Private Function f(x As Integer) As Boolean '自定义函数f,返回值为逻辑型
Dim j As Integer
f = True
For j = 2 To Int(Sqr(x))
If x Mod j = 0 Then
f = ③ '函数返回值
Exit For '跳出For循环
End If
Next j
End Function
程序中①划线处应填入
程序中②划线处应填入
程序中③划线处应填入
Private Sub Command1_Click()
Dim n As Integer,S As Integer
s=0
n=Val(Text1.Text)
If n>1 Then
For i=1 To n
s= ①
If n=s Then
Label1.Caption=Str(n)+”是一个三角形数。”
Exit For
②
Label1.Caption=Str(n)+”不是一个三角形数。”
Exit For
End If
Next i
Else
Label1.Caption=”请输入一个大于1的正整数”
End If
End Sub
① ②
图1
徐明设计了一个VB程序用于寻找这个以211开头、可被2012整除的6位数。其算法流程图如图2所示,程序界面如图3所示,程序的代码编辑窗口如图4所示。
图2
图5
图6
A.Dim k As Integer
B.For k = 211000 To 211999
C.Label2.Caption = Str(k)
编写一个验证哥德巴赫猜想的VB程序:程序运行时,在文本框Text1中输入一个大于或等于4的偶数,单击“验证”按钮Command1后,如果哥德巴赫猜想验证成功,则在文本框Text2中显示“Yes”,并在列表框List1中显示用两个素数表示该偶数的等式,否则显示“No”。程序运行效果如图所示。
实现上述功能的VB代码如下,但加框处代码有错,请改正。
Function judge(x As Integer)As Boolean
‘函数judge的功能是判断整数x是不是素数,若是素数则返回True,否则返回False
Dim j As Integer
judge=True
j=2
Do While j<=x-1 And judge=True
If x Mod j=0 Then
judge=False
Else
j=j+1
End If
Loop
End Function
Private Sub Command1_Click()
Dim n As Integer, p As Integer, q As Integer, flag As Boolean
n=Val(Text1.Text)
p=1
flag=False
Do While And p<n ‘
p=p+1
‘
If judge(p)And judge(q)Then
Text2.Text=“Yes”
flag=True
List1.AddItem Str(n)+“=”+Str(p)+“+”+Str(q)
End If
Loop
If flag=False Then
Text2.Text=“No”
End Sub
请在下面划线处填入合适的代码。
Private Sub Command1_Click()
Dim i,n,s,t,k As Integer 's为A类数的个数,t为二进制数中“1”的个数,k为“0”的
个数
s = 0
For i = 1To 1000
n = i:t = 0:k= 0
Do While n > 0
If ① Then t=t+1Else k=k+1
②
Loop
If t>k Then
List1.Addltem Str(i)
s = s+1
End If
Next i
Text1.Text=Str(s)
End Sub
①②
Dim i As Integer, a As Integer, b As Integer, c As Integer
For i=100 To
a=i\100
b=
c=i-100*a-10*b
If Then
Print i
End If
Next i
Private Sub Command1_Click()
Randomize '随机数初始化
Dim i As Long, n As Long, s As Long
Dim x As Double, y As Double, z As Double
n = Val(Text1.Text)
①
s = 0
Do While i <= n '随机投点n次
x = Rnd: y = Rnd
z = ②
If z <= 1 Then
s = s + 1
End If
i = i + 1
Loop
Text2.Text = ③
Private Sub Command1_Click()
Dim s As string
Dim n As Integer, w As Integer
s=Text1.Text
For i=1 To 3
n=Len(s):w=1
For j=2 To n
If ________ Then w=j Else Exit For
Next j
s=Mid(s,1,w-1)+Mid(s, w+l, n-w)
Next i
Text2.Text=s
End Sub
画线处的正确代码为( )
请回答下列问题:
Private Sub Command1_ Click()
Dim s As Long
Dim iAs Integer,a As Integer,b As Integer
For i=0 To 9999 Step
s=310000+i
If s Mod 46=0 Then
a=
b=s\ 10 Mod 10
If a=b Then List1. AddItem Str(s)
End If
Next i
End Sub