 License Public Domain
 Lines 32
##### Related SnortSnort PointSort, C++, Priority Queue Random Developments Project Euler 2 Project Euler 28
##### Permissions Owner: ragecage Group Owner: SnortSnort Viewable by Everyone Editable by All Siafoo Users Solve a problem – Filter by language, license, keyword, owner, or search text to find code & info fast.

# Fibonacci problem - Fortran 0

 In Brief This program outputs the sum of all even numbers in the Fibonacci sequence that are smaller than 4 Million
 Language Fortran
# 's
` 1! fibonacci.f95 2! Program to find the sum of all even Fibonacci numbers less than 4 million. 3 4 5program fibonacci 6 7implicit none 8! Define the variables. 9integer i,n(0:2000),sum1011print*, 'This program will find the sum of all even Fibonacci numbers'12print*, 'that have values less than 4 million.'131415! Initialize the Fibonacci Sequence.16n(0) = 117n(1) = 118! Initialize the Sum.19sum=020! Supply the first two lines of output.21print*, 'Number=', n(0), ' SUM=', sum22print*, 'Number=', n(1), ' SUM=', sum2324do i=2,200025! 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.28if(n(i).ge.4e6) then 29exit30end if31! Only add the latest number if it is even.32if(mod(n(i),2).eq.0) then 33sum=sum+n(i)34end if35! Print out the latest fibonacci number and the sum.36print*, 'Number=', n(i), ' SUM=', sum3738end do3940print*, 'Fibonacci number now larger than 4 million'4142end program fibonacci`

This program outputs the sum of all even numbers in the Fibonacci sequence that are smaller than 4 Million