2012年11月20日 星期二

vb選手第二次測試 3rd

請找出在long範圍內最大的費氏數,並找出它是第幾項。

3 則留言:

  1. Dim num(100) As Long
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\out.txt" For Output As #1
    num(1) = 1: num(2) = 2
    For i = 3 To 45
    num(i) = num(i - 1) + num(i - 2)
    Next
    Print #1, num(45)
    Close #1
    End
    End Sub

    回覆刪除
  2. Dim s(45) As Long
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\out.txt" For Output As #2
    s(0) = 1
    s(1) = 1
    i = 2
    For i = 2 To 45
    s(i) = s(i - 1) + s(i - 2)
    Next
    Print #2, "第" & i - 1 & "項 " & s(i - 1)
    Close #2
    End
    End Sub

    回覆刪除
  3. Dim s(45) As Long
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\out.txt" For Output As #1
    s(1) = 1: s(2) = 2
    For i = 3 To 45
    s(i) = s(i - 1) + s(i - 2)
    Next
    Print #1, "第45項" & s(45)
    Close #1
    End
    End Sub

    回覆刪除