Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …
Find the sum of all the even-valued terms in the sequence which do not exceed four million.
Solution:
Function Prob002() As Long
Dim Term1 As Long = 1
Dim Term2 As Long = 2
Dim tmpTerm As Long = 0
While Term1 < = 4000000
If Term1 Mod 2 = 0 Then Prob002 += Term1
tmpTerm = Term1 + Term2
Term1 = Term2
Term2 = tmpTerm
End While
End Function
Summary:
Even though it'll never be as exciting as in the movie Pi, I do love working with Fibonacci sequences.