Solve a problem – Filter by language, license, keyword, owner, or search text to find code & info fast.
|In Brief||This program outputs the sum of all even numbers in the Fibonacci sequence that are smaller than 4 Million|
2! Program to find the sum of all even Fibonacci numbers less than 4 million.
8! Define the variables.
11print*, 'This program will find the sum of all even Fibonacci numbers'
12print*, 'that have values less than 4 million.'
15! Initialize the Fibonacci Sequence.
16n(0) = 1
17n(1) = 1
18! Initialize the Sum.
20! Supply the first two lines of output.
21print*, 'Number=', n(0), ' SUM=', sum
22print*, 'Number=', n(1), ' SUM=', sum
25! Define the next number in the sequence.
26n(i) = n(i-1) + n(i-2)
27! Exit the loop if the latest number is greater than 4 million.
31! Only add the latest number if it is even.
35! Print out the latest fibonacci number and the sum.
36print*, 'Number=', n(i), ' SUM=', sum
40print*, 'Fibonacci number now larger than 4 million'
42end program fibonacci
This program outputs the sum of all even numbers in the Fibonacci sequence that are smaller than 4 Million