y=int(input(“请输入第2个数:”))
if x>y:
print(x)
else:
print(y)
程序运行后,键盘输入8和6,其输出结果为
For i = 1 To 6
a(i) = Int(Rnd * 20) + 1: b(i) = i
Next i
For i = 1 To 5
For j = i+1 To 6
If a(b(i))>a(b(j)) Then
t = b(j): b(j) = b(i): b(i) = t
End If
Next j
Next i
i = 1 : j = 6: s="" : Key = Val(Text1.Text)
Do While i <= j
m = (i + j) \ 2
If Key = a(b(m)) Then Exit Do
If Key < a(b(m)) Then j = m - 1 Else i = m + 1
s = s + Str(m)
Loop
Text2.Text = s
在文本框Text1中输入10,运行以上程序段后,文本框Text2中显示的内容为 3 5 4,则 a 数组中 a(1)到 a(6)各元素的值可能的是( )
①将324扩大100倍,32400只能被48695减去1次,则百位上的商是1;
②将324扩大10倍,3240能被前一次余的16295减去5次,则十位上的商就是5;
③对于324,不能被最后剩余的95减去,则个位上的商为0。所以最后的商的整数部分为150。
程序运行界面如图所示。

Dim s1, s2, s3, s, ans As String
Dim tot As Integer, t As Integer
Private Sub Command1_Click( )
Dim a, b, i, j, length As Integer
s1=Text1.Text:s2=Text2.Text:s3=""
Length=Len(s1)-Len(s2)
For i=1 To length
s2=s2+"0"
Next i
For i=0 To length
s=Mid(s2, 1, Len(s2)-1):tot=0
Do While ① or(Len(s1)=Len(s)And s1>=s)
tot=tot+1
ans="":flag=False
a=Len(s1):b=Len(s)
For j=a To 1 Step-1
t=0
If flag Then
t=-1:flag=False
End If
If b>0 Then
t=t+Val(Mid(s1, j, 1))-Val(Mid(s, b, 1))
Else
t= ②
End If
If t<0 Then
③
flag=True
End If
ans=t&ans:b=b-1
Next j
s1=Val(ans)
Loop
s3=s3&tot
Next i
i=1
Do While Mid(s3,i,1)="0"
i=i+1
Loop
Text3.Text=Mid(s3,i,Len(s3))
End Sub
以上程序段运行时,为了实现上述功能,画线处应填入的代码分别为:①;②;③。
①输入各点的坐标(最后一个点的坐标后不加逗号),存人变量a中;
②将原点坐标加到坐标序列a的最前端;
③以逗号为界从a中取出各点的坐标,存入列表b中;其中列表b中的第一个和第二个数字为第一个点的x坐标和y坐标,第三个和第四个数字为第二个点的x坐标和y坐标,以此类推;
④计算折线长度。若以b[]标记为相邻两个点中前者的x坐标,则b[i+2]为后者的x坐标,b[i+1]为前者的y坐标,b[i+3]为后者的y坐标。i最小值为0,最大值为len(b)-4,步长为2。运用for语句求折线长度。
程序如下:
from math import sqrt
a=input("请输入各点的坐标:")
① #补上原点坐标
b=a.splt(",") #取出各点的坐标
if len(b) %2== 1:
print("输入的坐标有误")
else:
s=0
for i in range(0, len(b)-2, ② ):
s=s+sqt((int(b[i+2])-int(b[i])* *2+(int(b[i+3])-int(b[i+1])**2)
else:
print("折线长度为:", s)
if (a%3=0) Or (b%3=0) :
c = a * b
else:
c = a + b
执行后变量c的值为( )
Private Sub Comand1_Click( )
Dim s As String, c As String
Dim t As Integer, I As Integer
Dim a(1 To 26)As Integer
s=Text1.Text
For i=1 to 26
a(i)=0
Next i
i=1
Do While i<=Len(s)
c=Mid(s, i, 1)
If ① Then
t=Asc(c)-96
Else
t=Asc(c)-64
End If
If a(t)=0 Then
a(t)=1
Else
②
End If
i=i+1
Loop
Label1.Caption=s
End Sub
① ②
小王利用VB程序实现这一加密功能,程序界面和代码如下所示:
Private Sub Com_ jm_ Click()
Dim x As String, ch As String, cl As String
Dim s1 As String, s2 As String, s As String
Dim i As Integer, n As Integer, y As Integer
x= Text1. Text
n=Len(x)
For i=1 To n
ch= Mid(x, i, 1)
If ch >= "0" And ch <= "9" Then
①
s2=s2 & y
Elself ch >="a" And ch<="z" Then
y=(Asc(ch)-Asc("a")+3) Mod 26
②
s1=c1+s1
Else
y=(Asc(ch)- Asc("A")+3) Mod 26
c2=Chr(Asc("A")+y)
s1=c2+s1
End If
Next i
③
Text2 Text=s
End sub
① ② ③
s1 = "00100100" : s2 = "" : flag = True
For i = Len(s1) To 1 Step -1
ch = Val(Mid(s1, i, 1))
If flag Then
s2 = Str(ch) + s2
If ch = 1 Then flag = False
Else
s2 = Str(1 - ch) + s2
End If
Next i
Label1.Caption = s2
执行该程序段后,标签Label1中显示的内容是( )
Dim i As Integer, t As Integer
Dim enc As String, dec As String
enc = " 6Z9FBQ3VX4": dec =" "
i =1:t=0
Do While t <4
c = Mid(enc, i,1)
If c>="0" And c<="9" Then
i = Val(c)
Else
dec=dec+c
t=t+1
End If
i =i+1
Loop
Text1.Text=dec
运行该程序段,文本框Text1中的内容是( )
m=1
n=2
if true then print m else print n
s =“312321”:m=0:c=“”:k=1
For i=1 To Len(s)
m=m+k
If k=1 Then c=Mid(s,n,1)+c Else c=c+ Mid(s,m,1)
If i Mod 3=0 Then k=-k:m=Len(s)+1
Next i
执行该程序段后。变量c的值是( )
s1 = Text1.Text: s2 = Text2.Text
For i = 1 To Len(s1)
ch1 = Mid(s1, i, 1): ch2 = Mid(s2, i, 1)
f(Asc(ch1) - Asc("a") + 1) = f(Asc(ch1) - Asc("a") + 1) + 1
⑴
Next i
flag = True
For i = 1 To 26
If f(i) <> 0 Then ⑵ : Exit For
Next i
If ⑴ Then Label1.Caption = "Yes" Else Label1.Caption = "No"
上述程序段中方框处被选语句为:
①f(Asc(ch1) - Asc("a") + 1) = f(Asc(ch1) - Asc("a") + 1) + 1
②f(Asc(ch2) - Asc("a") + 1) = f(Asc(ch2) - Asc("a") + 1) – 1
③flag = True
④flag = False
则(1)(2)(3)处语句依次为( )
Private Sub Command1_Click()
n = Val(Text1.Text)
For i=2 To n
For j= 2 To sqr(i)
If i Mod j=0 Then Exit For
Next j
If j>Sqr(i) Then Print i
Next i
End Sub
该事件过程的功能是( )
Const n=10
Dim a(1 To 10) As Integer
Private Sub Form_Load()
'生成n个有序数,显示在List1中,代码略
End Sub
Private Sub Command1_Click()
Dim t As Integer,i As Integer,j As Integer,temp As Integer
For i=t+1 To n
temp=a(i)
For j=i To i+1-t Step-1
Next j
a(j)=
Next i
For i=1 To n
List2.AddItem Str(a(i))
Next i
End Sub
s="491053”
For i=1 To 3
n=Len(s)
k=1
For j=2 To n
If Mid(s, k, 1) > > = Mid(s, j, 1) Then
k=j
Else
Exit For 'Exit For表示退出循环
End If
Next j
s= Mid(s, 1, k-1)+ Mid(s, k+1, n- k)
Next i
Label1.Caption= s
执行该程序段后,标签Labe1中显示的值是( )
sentence=input('请输入一段文字:')
for i in sentence:
if i=='密':
continue
print(i,end='')
现编写程序,实现如下功能:输入一个正整数,输出该数的阶乘。程序运行如下图所示。
请在画线处填入合适的代码:
n=int(input('请输入一个正整数:'))
s=1
if n!=0:
for i in range() :
s=
print('阶乘为:',s)
amin= a(1) : amax=a(1)
i=2 : j=9
Do While i <= j
If a(i) > a(j) Then
Else
End If
i=1 : j=j-1
Loop
Text 1. Text= Str(amin)+"," Str(amax)
上述程序段中方框处可选语句为:
①If a(j)>amax Then amax =a(j)
②If a(j)< amin Then amin =a(j)
③If a(i)<amin Then amin =a(i)
④If a(i)>amin Then amin =a(i)
则(1)(2)(3)(4)处语句依次可为( )
小李为了解决该问题,首先结合数组a的有序性,找出a,b两个数组中要剔除的m个数据,再将数组b中保留的数据插入到数组a中。示例如下:
|
n=10,数组a:2,4,6,8,10,12,14,16,18,20 m=5,数组b:41 , 11,17 , 29,9 处理后的数组a:2,4,6,8,9 , 10,11 , 12,14,16 |
Const n=1000,m=50
Dim a(1 To n)As Integer, b(1 To m)As Integer
Function getImax(k As Integer)As Integer
‘在数组元素b(1)~b(k)中找出值最大的元素,返回其下标,代码略
End Function
Private Sub Commandl_Click( )
Dim i As Integer, j As Integer, k As Integer
Dim na As Integer, nb As Integer, imax As Integer, mean As Integer
‘读取数据分别存入数组a、b,代码略
na=n : nb=m
imax=getImax(nb)
For i=1 To m
If a(na)<= Then
b(imax)=b(nb)
nb=nb-1
If nb>0 Then imax=getImax(nb)
Else
na=na-1
End If
Next i
Do While nb>0
i=1 : j=na
imax= getImax(nb)
Do While i<=j
mean =(i+j)\2
If a(mean)<b(imax) Then i= mean +1 Else j=mean-1
Loop
For k=na To 1 Step-1
Next k
a(i+nb-1)=b(imax)
b(imax)=b(nb)
nb=nb-1
Loop
'输出数组a,代码略
End Sub