 License Public Domain
 Lines 30
##### 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 You are viewing an old version of this snippet. View Latest Version

# 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),sum10111213! Initialize the Fibonacci Sequence.14n(0) = 115n(1) = 116! Initialize the Sum.17sum=018! Supply the first two lines of output.19print*, 'Number=', n(0), ' SUM=', sum20print*, 'Number=', n(1), ' SUM=', sum2122do i=2,200023! Define the next number in the sequence.24n(i) = n(i-1) + n(i-2)25! Exit the loop if the latest number is greater than 4 million.26if(n(i).ge.4e6) then 27exit28end if29! Only add the latest number if it is even.30if(mod(n(i),2).eq.0) then 31sum=sum+n(i)32end if33! Print out the latest fibonacci number and the sum.34print*, 'Number=', n(i), ' SUM=', sum3536end do3738print*, 'Fibonacci number now larger than 4 million'3940end program fibonacci`

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