我要寫一個程式可以計算出30位數的費西伯那序列數最大值
費西伯那:
設a,b等於1
a=a+b
b=b+a
一直循環到30位數最大值
例:
a=1+1=2+3=5+8=13
b=1+2=3+5=8+13=21
-----------------------------------------------------------------
希望有人能教我一下
最好是能在程式碼旁邊附上註解~好讓我了解邏輯
感激不盡~
2006-11-23 04:50:50 · 5 個解答 · 發問者 ? 1 in 電腦與網際網路 ➔ 程式設計
那個......
F大
你貼的那篇跟我的題目意思不同耶....
我要的是求出30位數的費西伯納列數最大值
就像2位數最大值是89
一位數最大值是8
......
2006-11-23 06:05:50 · update #1
Private Sub Command1_Click() Dim A$(1), N%, I$, S$, K% K = Abs(Int(Val(InputBox("請輸入位數", "", 30)))) N = 1: A(0) = 0: A(1) = 1 Do I = S: S = A(1) A(1) = Add(A(0), A(1)) A(0) = S: S = A(1) N = N + 1 Loop Until Len(S) > K N = N - 1: S = I Cls Print K & "位數之費氏序列最大值為第"; N; "項" Print "其值為:"; SEnd SubFunction Add$(ByVal A$, ByVal B$)'大數加法 Dim K$, M%, T%, J%, F% If Len(A) < Len(B) Then K = A: A = B: B = K M = Len(B): T = 0 For J = Len(A) To 1 Step -1 If M > 0 Then T = T + Mid$(B, M, 1) F = T + Mid$(A, J, 1) Mid$(A, J, 1) = F Mod 10 M = M - 1: T = F \ 10 If M = 0 And T = 0 Then Exit For Next If T Then A = T & A Add = AEnd Function
2006-11-23 08:41:22 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
記得要拉一個Command、一個Label、一個TextBox~這樣介面比較完整~可以直接複製程式碼~希望對你有幫助^^( & 不知為什麼~空白會被吃掉~麻煩你自己拉一下嘿~)
Public Function f(n As Integer) As Integer
Select Case n
Case 1
f = 1
Case 2
f = 1
Case Else
f = f(n - 1) + f(n - 2)
End Select
End Function
Private Sub Command1_Click()
Dim a As Integer
a = Val(Text1.Text)
t = 0
For i = 1 To a
t = t + f(Val(i))
Next i
a = f(a)
Label2.Caption = "第" & Text1.Text & "項為" & a & " / 到第" & Text1.Text & "項的和為" & t
End Sub
2006-11-23 06:57:58 · answer #2 · answered by 阿皓 2 · 0⤊ 0⤋
是這篇才對
http://tw.knowledge.yahoo.com/question/?qid=1206112102873
2006-11-23 05:57:50 · answer #3 · answered by jj0900 1 · 0⤊ 0⤋
這好像不太一樣耶...
2006-11-23 05:53:36 · answer #4 · answered by ? 1 · 0⤊ 0⤋
可參考這篇:
http://tw.knowledge.yahoo.com/question/?qid=1206112204891
2006-11-23 05:20:32 · answer #5 · answered by ? 6 · 0⤊ 0⤋