Private Sub Command1Click()
Dim Year As Integer
①
If (Year Mod 4 = 0) And (Year Mod 100 <> 0) Or (Year Mod 400 = 0) Then
Text2.Text = "是闰年"
Else
Text2.Text = "不是闰年"
End If
End Sub
为实现上述功能, 程序①加框处应填写为
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer
a = Val(text1.Text)
b = Val(text2.Text)
c = (a + b + Abs(a - b)) \ 3
Text3.Text = Str(c)
End Sub
运行该程序,分别在文本框Text1、Text2中输入5、9,单击命令按钮Command1后,文本框Text3中显示的内容是( )
Private Sub Command1_Click()
Dim I As Integer
I=
If I >= 0 And I <= 50 Then
Text2.Text = "空气质量一级 优"
ElseIf I >= 51 And I <= 100 Then
Text2.Text = "空气质量二级 良"
ElseIf I >= 101 And I <= 150 Then
Text2.Text = "空气质量三级 轻度污染"
ElseIf I >= 151 And I <= 200 Then
Text2.Text = "空气质量四级 中度污染"
ElseIf I >= 201 And I <= 300 Then
Text2.Text = "空气质量五级 重度污染"
ElseIf Then
Text2.Text = "空气质量六级 严重污染"
Else
Text2.Text = "输入错误,请重新输入!"
End Sub
Private Sub Command1_Click( )
Dim x As Integer,y As Integer
x = 8
y = 10^x
Text1.Text = Str(y)
End Sub
运行程序时,单击Command1后弹出如上图所示的出错提示,引起该错误的原因是( )
Private Sub Command1_Click()
Dim S As String
Dim n As Integer
Dim cnt As Integer
Dim i As Integer
Dim num As Single
Dim cd As Single
Dim ave As Single
s=Text1.Text
n=Len(s)
hum=0
cd=0
cnt=0
For i=1 To n
①
If c>“a”And c<=“z” Or c>=“A”And c<=“Z”Then
cnt=cnt+1
Elself c>=”0”And c<=”9”Then
cnt=cnt+1
Else
If cnt>0 Then
num=num+1
cd=cd+cnt
②
End If
End If
Next i
If cnt>0 Then
num=num+1
cd=cd+cnt
End If
Ave=cd/num
Label1.Caption=“总共有”+Str(num)+“个单词,平均长度为”+Str(ave)
End Sub
① ②
s=Text1.Text
s1=" "
For i=1 To Len(s)
c=Mid(s, i, 1)
If c>="A" And c<="Z" Then
c=Chr(Asc(c)+32) '大写字母转化为小写字母
End if
s1=s1+c
Next i
Text2.Text=s1
在文本框Textl中输入"ABcd12XY ",执行上述程序段后,文本框Textl显示的内容是( )
i = 1: j = 7: s = ""
key = 34
Do While i <= j
m = (i + j) \ 2
If key = a(m) Then
s = s + "2": Exit Do 'Exit Do 表示退出循环
ElseIf key < a(m) Then
j = m - 1: s = s + "1"
Else
i = m + 1: s = s + "3"
End If
Loop
Text1.Text = s
数组元素a(1)到a(9)的值依次为“15,26,34,47,53,59,60,72,85”。若该程序段执行后,文本框Text1中显示的内容可能是( )
1)对于两个形状相同的矩阵,它们的内积是每个对应位置的数字相乘之后的和;
2)对于小矩阵和大矩阵卷积运算时,以小矩阵为参考,沿着横向和纵向两个方向逐个滑动(取同样大小的矩阵),依次横向和纵向两个方向逐个滑动(取同样大小的矩阵),依次求出内积,得到结果矩阵,如图a所示。
图a
小A同学用VB程序模拟上述的矩阵卷积运算,单击“初始化小矩阵”按钮command1,随机生成小矩阵数据,单击“初始化大矩阵”按钮command2,随机生成大矩阵数据,单击“运算”按钮command3,进行矩阵卷积运算并生成结果矩阵,运行界面如图b所示:
图b
Const m = 2 ‘小矩阵行数和列数
Const n = 8 ‘大矩阵行数和列数 Dim a(1 To m * m) As Integer Dim b(1 To n * n) As Integer
Dim tempStr As String ‘输出行的临时数据 '初始化小矩阵
Private Sub Command1_Click()
Dim x As Integer ‘小矩阵当前坐标位置
Randomize
List1.Clear
For i = 1 To m
tempStr = ""
For j = 1 To m
x = (i - 1) * m + j
a(x) = Int(Rnd() * 5 + 1) ‘小矩阵[1,5]的随机数
tempStr = tempStr + Str(a(x))
Next j
List1.AddItem tempStr
Next i End Sub
‘初始化大矩阵
Private Sub Command2_Click()
Dim x As Integer ‘大矩阵当前坐标位置
Randomize
List2.Clear
For i = 1 To n
temp Str = ""
For j = 1 To n
x =
b(x) = Int(Rnd() * 10) ‘大矩阵[0,9]的随机数
tempStr = tempStr + Str(b(x))
Next j
List2.AddItem tempStr
Next i
End Sub
‘运算
Private Sub Command3_Click()
Dim productSum As Integer '内积
Dim product As Integer
Dim rowNow As Integer, colNow As Integer
List3.Clear
For i = 1 To n - m + 1 ‘处理纵向移动
tempStr = ""
For j = 1 To n - m + 1 ‘处理横向移动
productSum = 0
For k = 1 To m * m
rowNow = (k - 1) \ m ‘小矩阵值的行号
colNow = ‘小矩阵值的列号
product = a(k) * b((i - 1 + rowNow) * n + j + colNow - 1) '大小矩阵值乘积
Next k
tempStr = tempStr + Str(productSum)
Next j
List3.AddItem tempStr
Next i
End Sub
实现上述功能的VB程序如下:
Private Sub Command1_Click()
List1.Clear
Dim five(1 To 5) As Integer
Dim i As Integer, j As Integer, k As Integer
Dim p As Integer, find_pair As Boolean
'随机抽取5张牌,将牌的点数存储在数组five中,并在List1中显示。代码略
i = 5: p = 1: find_pair = False
Do While i>= 2
j=p
Do While j <= i - 1
If five(j) > five(j + 1) Then
t = five(j): five(j) = five(j + 1): five(j + 1) = t
ElseIf five(j) = five(j + 1) And Not find_pair Then
t = five(1): five(1) = five(j): five(j) = t
t = five(2): five(2) = five(j + 1): five(j + 1) = t
find_pair = True
i = i + 1
p = _____________
Exit Do
End If
j = j + 1
Loop
i = i - 1
Loop
k = 0
For i = 3 To 4
If Then k = k + 1
Next i
If five(1) = five(2) And k = 2 Then
Label1.Caption = "运气不错:)"
Else
Label1.Caption = "运气一般:|"
End If
End Sub
请回答下列问题:
Private Sub Command1_Click()
Dim dx As String, dw As String
Dim st As String, ch As Integer
Dim i ,n As Integer
dx = "零壹贰叁肆伍陆柒捌玖"
dw = "亿仟佰拾萬仟佰拾圆"
st = Text1.Text : n = Len(st)
If n > 9 Then
Text2.Text = "输入的数据超出所能转换的范围"
Else
For i = 1 To n
ch = ①
s = s + Mid(dx, ch + 1, 1) + Mid(dw, ② , 1)
Next i
Text2.Text = s + "整"
End If
End Sub
以上程序段运行时,为了实现上述功能,划线处应填入的代码分别为:
①; ②;
Dim a(1 To 10)As Integer
Dim i As Integer, s as string
a(1)=1
For i =2 To 10
a(i)=a(i-1)*i
s=St(a(i))
Dim a(10) As Integer
Dim I As Integer
a(1)=1
a(2)=1
For i=3 To 6
a(i)=a(i-1)+a(i-2)
Next i
Print a(6)
上述程序运行后,输出a(6)的值是。
Dim a(10) as Integer
Dim i As Integer
Dim s As Integer
For i=1 to 5
a(i)=i*1
Next i
s=a(3)+a(4)
Print s
上述程序运行后,变量s的值是 。
“完数”是指一个自然数恰好等于它的因子(不包含本身)之和。如6的因子为1,2,3,而6=1+2+3,因此6就是完数。再如28的因子为1,2,4,7,14,而28=1+2+4+7+14,因而28也是完数。
问题:输入一个正整数n,判断该正整数是否为完数。
要判断一个正整数n是否为完数,最简单的方法是:求出1到n-1之间的所有因子和为Sum,如果Sum的值和n的值相同,则n就是完数。
以下代码是判断n是否为完数的程序片段,请你补全代码:
Dim n As Long
Dim Sum As Long ‘Sum用来记录n的因子和
n = InputBox(“n=”)
For i = 1 To n-1 ‘求n的因子和Sum
If n Mod i = 0 Then Sum =
Next i
If Then
Print n & “是完数”
Else
Print n & “不是完数”
End If
Private Sub Command1_Click()
Dim a As String, b As String, c As String
a = InputBox("请输入a的值")
b = InputBox("请输入b的值")
c = a + b
Print c
End Sub
Private Sub Command1_Click()
Dim i As Integer
Dim a(10) As Integer ‘①
For i = 1 To 10 ‘②
a(i) = Rnd * 100 ‘③
Next i
Label1.Caption = Str(a(i)) ‘④
End Sub
a,b,c,d=input( ).split( )
a=int(a)
b=int(b)
c=int(c)
d=int(d)
print(c)
如果输入的是4 3 6 9,则程序运行的结果为( )
Const n = 5
Dim b(n)As Integer
For i = 1 To 5
b(i)= i
Next i
For i = 1 To 2
For j = n – 1 To I Step -1
If a(b(j))> a(b(j + 1))Then
t = b(j):b(j)=b(j + 1):b(j + 1)= t
End If
Next j
Next i
数组元素a(1)~a(5)的值依次为“35,24,45,16,77”,运行上述程序段后,数组元素b(1)到b(5)的值依次为( )
Dim a(1 To 10) As Integer
Dim max As Integer
max=0
For i=1 To 10
If a(i)>max Then max=a(i)
Next i
Label1.Caption =“最大值是:”+ Str (max)
运行该程序时发现,当输入10个正整数时可以得到正确结果,但当输入10个负整数时结果错误。将上述程序段中相应语句仅进行一次更改,就可实现输入10任意整数都能得到最大值的结果,则下列修改正确的是( )