早教吧作业答案频道 -->其他-->
有一个数列前两项为1,从第三项开始,每一项均为前两项之和,求次数列第20个数.(用递归实现)OptionExplicitFunctionfact(n)AsDoubleDima(n)AsSingle,i%Fori=1To2a(i)=1NextiFori=3To20a(i)=a(i-
题目详情
有一个数列前两项为1,从第三项开始,每一项均为前两项之和,求次数列第20个数.(用递归实现)
Option Explicit
Function fact(n) As Double
Dim a(n) As Single, i%
For i = 1 To 2
a(i) = 1
Next i
For i = 3 To 20
a(i) = a(i - 1) + a(i - 2)
Next i
fact = a(i)
End Function
Private Sub Command1_Click()
Dim n As Integer, m As Double
m = fact(n)
Label1.Caption = m
End Sub
请问那里出现错误,急需解决
Function fact(n) As Double
If n > 3 Then
fact = fact(n - 2) + fact(n - 1)
Else
fact = 1
End If
End Function
Private Sub Command1_Click()
Dim n As Integer, m As Double
n = Val(Text1.Text)
If n < 0 Then
Exit Sub
End If
m = fact(n)
Label1.Caption = m
End Sub
Option Explicit
Function fact(n) As Double
Dim a(n) As Single, i%
For i = 1 To 2
a(i) = 1
Next i
For i = 3 To 20
a(i) = a(i - 1) + a(i - 2)
Next i
fact = a(i)
End Function
Private Sub Command1_Click()
Dim n As Integer, m As Double
m = fact(n)
Label1.Caption = m
End Sub
请问那里出现错误,急需解决
Function fact(n) As Double
If n > 3 Then
fact = fact(n - 2) + fact(n - 1)
Else
fact = 1
End If
End Function
Private Sub Command1_Click()
Dim n As Integer, m As Double
n = Val(Text1.Text)
If n < 0 Then
Exit Sub
End If
m = fact(n)
Label1.Caption = m
End Sub
▼优质解答
答案和解析
Function fact(n) As Double
If n > 2 Then
fact = fact(n - 2) + fact(n - 1)
Else
fact = 1
End If
End Function
Private Sub Command1_Click()
Dim n As Integer,m As Double
n = Val(Text1.Text)
If n < 0 Then
Exit Sub
End If
m = fact(n)
Label1.Caption = m
End Sub
If n > 2 Then
fact = fact(n - 2) + fact(n - 1)
Else
fact = 1
End If
End Function
Private Sub Command1_Click()
Dim n As Integer,m As Double
n = Val(Text1.Text)
If n < 0 Then
Exit Sub
End If
m = fact(n)
Label1.Caption = m
End Sub
看了有一个数列前两项为1,从第三项...的网友还看了以下:
请你观察、思考下列计算过程:因为11一=1一1,所以1一1=11;&n1sp;因为111一=1一3 2020-04-07 …
1.一个圆柱和一个圆锥等底等高,体积相差3.6dm²,圆柱体积?2.用三个正方体粘成一个长方体,长 2020-04-26 …
1.一桶油,第一次用去2/5,第二次用去1/3,还剩8千克.这桶油多少千克?2.一桶油,第一次用去 2020-05-20 …
写出下列比喻类的歇后语1.一个教师一路拳——2.一个巴掌拍不响——3.一肚子加减乘除——4.一盘象 2020-05-21 …
1.一年365天,请用科学记数法表示一年有多少秒?2.一人的心跳速度为每分70次,一年跳多少次?字 2020-05-23 …
科学1道计算题一列火车重1.47×107牛顿,以180千米/时的速度在平直的轨道上匀速行驶,如果列 2020-06-07 …
一列火车自A城驶往B城,沿途有n个车站(包括A、B两个车站),该列车挂有一节邮政车厢,运行时需要在 2020-06-20 …
“一带一路”铸就辉煌新闻视角,央视新闻联播从2015年4月4日起推出系列报道《一带一路共建繁荣》第 2020-06-25 …
一列车由等长的车厢连接而成,车厢之间的间隙可忽略不计.一人站在站台上与第一节车厢的最前端相齐,当列 2020-07-06 …
将-4.-3.-2.-1.0.1.2.3.4这9个数字填入九字方框中使得不关怎么样加起来都得零1一 2020-07-06 …