请完善下列程序代码:
Function prime(x As Integer) As Boolean ’此函数判断x是否为质数
prime = True
For i = 2 To Int(Sqr(x))
If Then prime = False: Exit For
Next i
End Function
Private Sub Command2_Click()
Dim a As Integer, b As Integer
Dim n As Integer
For a = 2 To n \ 2
b = n - a
If Then
List1.AddItem Str(a) + " " + Str(b) + " " + Str(n)
End If
Next
End Sub
Function fg(n as Integer)As Integer
If n=1 fg=1
If n=2 fg=2
If n>=3 fg=fg(n-1)+fg(n-2)
End Function
请问走完这8阶楼梯的走法有( )
Function f(n As Integer) As Long
If n = 1 Then
f =5
Else
f =2 * f(n - 1) - 3
End If
End Function
Private Sub Command1_click()
Dim n As Integer
n = Val(Text1.Text)
Text2.Text = Str(f(n))
End Sub
该程序段运行后,在文本框Text1中输入5,单击命令按钮Command1后,文本框Text2中显示的是( )
Private Sub Command1_Click()
Dim x As Integer
x = Val(Text1.Text)
Label1. Caption = Str(x)+ prime(x, 2)
End Sub
Function prime(n As Integer, m As Integer) As String
If n = m Then
prime = "是素数。"
ElseIf n < 2 Or n Mod m = 0 Then
prime = "不是素数。"
Else
prime = prime(n, m +1)
End If
End Function
在文本框Text1中输入的值是123,并执行程序后,自定义函数prime被执行的次数是( )
Function f(a As Integer, b As Integer) As Integer
Dim k As Integer
k = a Mod b
If k = 0 Then
f = b
Else
f = f(b, a mod b)
End If
End Function
Private Sub Command1_Click()
Dim i As Integer, j As Integer
i = Val(Text1.Text)
j = Val(Text2.Text)
Text3.Text = Str(i * j / f(i, j))
End Sub
该程序运行之后,在text1与text2分别输入25 与15,点击command1后在text3上显示的内容为( )
Function f (n As Integer) As Long
If n = 1 Then
f = 5
Else
f= 2*f(n-1) – 3
End If
End Function
Private Sub Command1_click()
Dim n As Integer
n = Val (Text1.Text)
Text2. Text = Str(f(n))
End Sub.
该程序段运行后,在文本框Text1中输入5,单击命令按钮Command1后,文本框Text2中显示的是( )
Private Function f(x As Single, n As Integer)As Single
If n=0 then
f=1
Else
If n Mod 2=1 then
f=x*f(x,n\2)
Else
f=f(x,n\2)\x
End If
End If
End Function
Private Sub Command1_Click( )
Label1.Caption=Str(f(4,6))
End Sub
程序运行时,单击按钮Command1,标签Label1显示的内容是( )
Private Sub Command1_Click( )
Dimi As Integer, s As Integer
s=0
For i=1 To 3 Step 2
s=s+f(i)
Next i
Text1. Text=Str(s)
End Sub
Function f(n As Integer) As Integer
If n=1 Then
f=2
Else
f=f(n-1)+n
End If
End Function
执行该程序段后,s的值为( )
def add(x):
if x>0:
return x+add(x-l)
else:
return 0
result=add(10)
print(result)