实现上述功能的VB程序代码如下,但加框处语句有误,请改正。
Private Sub Command1_Click()
Dim i As Integer, n As Integer, s As String
n = Val(Text1.Text)
s = “”
For i = 1 To
‘①
If i<= n Then
s = s + Str(n - i + 1)
Else
‘②
End If
Next i
Text2.Text = s
End Sub
程序中①处应改为;
程序中②处应改为。

c = 1: s = 10
Do While c <= s
For i = s To c + 1 Step -1
If
Then
t = a(i - 1): a(i - 1) = a(i): a(i) = t
End If
Next i
For i= ![]()
If
Then
t = a(i + 1): a(i + 1) = a(i): a(i) = t
End If
Next i
c = c + 1
s = s - 1
Loop
上述程序段三个方框处的语句分别为( )
m=a(1):s=0
For i= 2 To 5
If a(i) >m The nm=a(i)
s=s+m
If a(i) <m The nm=a(i)
s=s+m
Next i
数组元素a(1)到a(5)的值依次为“1,2,3,1,2”,执行该程序段后变量s的值为( )
S=0
For i=1 To 10
If i mod 2=0 Then S=S+i
Next i
Print “S=”;S
在VB中常用的字符串截取函数有:
| 函数名 | 功能 | 示例 | 结果 |
| Mid(s, m, n) | 从字符串s的第m位开始,截取长度为n的字符 | Mid(“ABCDEFG”,5,2) | “EF” |
| Left(s, n) | 截取字符串s左边n个字符 | Left(“ABCDEFG”,3) | “ABC” |
| Right(s, n) | 截取字符串s右边n个字符 | Right(“ABCDEFG”,2) | “FG” |
假如某人身份证号码S=“370102199602190000”,如果需要根据此人身份证号码求出该人的“出生年月日”。下列表达式不能实现的是( )。
Private Sub Command1_ Click ()
Dim a(1 To 10) As Integer, i As Integer, k As Integer
a(1)=1:a(2)=17:a(3)=8:a(4)=9:a(5)=18
a(6)=15:a(7)=20:a(8)=13:a(9)=7:a(10)=11
k=0
For i= 2 To 9
If(a(i)-a(i-1))*(a(i+1)-a(i))< 0 Then k=k+1
Next i
Text1. Text = Str (k)
End Sub
该程序段运行后后,文本框Text1中显示的内容是( )
Dim i As Integer, imax As Integer
①
For i = 3 To 10
If Abs(a(i) - a(i - 1)) >= ② Then imax = i
Next i
Text1.Text = "GDP变化最大的年份区间是" + Str(imax + 2008) + "-" + Str(imax + 2009)
①、②应填入的代码为( )
Function Leap(y As Integer)As Integer
If y Mod 100=0 Then
If y Mod 400=0 Then Leap=1 Else Leap=0
Else
If y Mod 4=0 Then Leap=1 Else Leap=0
End If
End Function
s1=Text1.Text: s2=Text2.Text
n=Len(s1): i=1: j= 1
Do While i<n+j-1 And j<=Len(s2)
If Mid(s1, i, 1)<Mid(s2, j, 1) Then
①
Else
s1= Mid(s1, 1, i-1)+Mid(s2, j, 1)+ Mid(s1, i, n+j-i)
②
End If
Loop
If ③ Then s1=s1+Mid(s2, j, len(s2)-j+1)
Text2.Text=s1
横线①②③处的代码为( )
string-input("输入字符串:")
c=1
p=1
while p <= len(string)-1:
if ①
c+= 1
else:
s += str(c)+string[p-1]
②
p+=1
print("压缩后数据为:" ,s)
① ②
|
错误结果 |
修改代码并说明原因 |
|
输入字符串:RRRRRGGBBBBBB 压缩后数据为: 5R2G |
import random
def check(a):
b=[0]*10 #初始化列表b,列表元素为10个0
for i in range(0,len(a)):
①
return b
list=[0]*30
for i in range(0,30):
num = random.randint(0,9)
②
print(list)
print("0~9数字依次出现次数.:" ③ )
① ② ③
输出数组的最大值。
arr1 =[12, 435, 76, 24, 78, 54, 866, 43]
= -32768
for i in range(0,7):
if arr1[i] > max1 : max1 =
print("最大值是:",)
input("运行完毕,请按回车键退出...")
|
内码(十六进制) |
CA |
B1 |
|
二进制 |
11001010 |
10110001 |
|
后5位十进制 |
10 |
17 |
|
前3位十进制 |
6 |
5 |
|
加密结果 |
10,6,17,5 |
|
按照上述规则,小明设计了一个解密的VB程序,功能如下:单击“解密”按钮,程序依次将文本框Text1中的字符提取,进行解密处理,并输出在文本框Text2中,程序效果如图a所示,请回答下列问题
Private Sub Command1_Click()
Const n = 100
Dim s As String, ch As String, nm As String
Dim p As Integer, i As Integer, k As Integer, t As Integer Dim a(1 To n) As Integer
s = Text1.Text p = 0: k = 0
For i = 1 To Len(s)
ch = Mid(s, i, 1)
If ch >= "0" And ch <= "9" Then
Else
If k Mod 2 = 1 Then
Else
a(k+1) = p
End If
k = k + 1:p = 0
End If
Next i
a(k + 1) = p * 32 + a(k)
For i =
nm = nm + dtoh(a(i))
Next i
Text2.Text = nm
End Sub
Function dtoh(x As Integer) As String Const
st1 = "0123456789ABCDEF"
Do While x > 0
x = x \ 16
Loop
End Function
实现上述功能的程序如下,请在划线处填入合适的代码。
c=input("请输入需要加密的字符(大写或小写字母):")
if "a"<=c<="z":
x=
if x>122:
else:
x=ord(c)-1
if :
x=90
print(c+"的加密字符为:",chr(x))
s=['seashell', 'gold', 'brown', 'purple', 'tomato']
print(s[2][1:4])