试题 试卷
题型:单选题 题类:常考题 难易度:普通
Dim a(1 to 1000)as long, n as integer
n=Val(Text1.Text)
a(1)= 1:a(2)= 1
For i=3 to n
a(i)= a(i-1)+a(i-2)
Next i
Label1.Caption=“斐波那契的第”&Str(n)&“是”&a(n)
该程序用到了下列哪一个算法( )
收藏 纠错
组卷次数:2次 +选题
Function f(n As Integer)As Long
Text1.Text=Trim(Str(n))+Text1.Text ‘函数Trim的作用是去掉字串首尾空格
If n=1 Then
f=1
Else
f=3*f(n\2)
End If
End Function
Private Sub Command1_Click()
Text1.Text=“”
Text1.Text=Trim(Str(f(8)))+Text1.Text
End Sub
单击按钮Command1后,文本框Text1中显示的值是( )
Dim k As Integer,a As Integer,b As Integer
a=Val(Text1.Text)
b=Val(Text2.Text)
Label1.Caption=trans(a,b)
Function trans(m As Integer,n As Integer)As String
If m<>0 Then
r=m Mod n
trans=trans(m\n,n)+Str(r)
trans=0
程序运行时,在文本框Text1和Text2中分别输入11和2,则Label1中的输出结果是( )
Dim i As Integer, sum As Integer
Dim a(1 To 6) As Integer, b(1 To 6) As Integer
sum = 0
a(6) = 18: a(5) = 7: b(6) = 14: b(5) = 16
For i = 4 To 1 Step -1
a(i) = a(i + 2) - a(i + 1)
b(i) = b(i + 2) - a(i)
If b(i) Mod 3 = 0 Then sum = sum + b(i)
Text1.Text = Str(sum)
该程序段运行后,文本框Text1中显示的内容是( )
F(1)=3
F(n)=F(n-1)*2
试题篮