License Public Domain
Lines 23
Permissions
Owner: ragecage
Group Owner: SnortSnort
Viewable by Everyone
Editable by All Siafoo Users
Hide
Writing an article is easy - try our reStructured Text demo Join Siafoo Now or Learn More
Note: You are viewing an old version of this snippet. View Latest Version

Fibonacci problem - Fortran Atom Feed 0

In Brief This program outputs the sum of all even numbers in the Fibonacci sequence that are smaller than 4 Million
# '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 single and double precision variables.
9integer i,n(0:2000),sum
10
11n(0) = 1
12n(1) = 1
13
14
15sum=0
16print*, 'Number=', n(0), ' SUM=', sum
17print*, 'Number=', n(1), ' SUM=', sum
18
19do i=2,2000
20
21n(i) = n(i-1) + n(i-2)
22
23if(n(i).ge.4e6) then
24exit
25end if
26
27if(mod(n(i),2).eq.0) then
28sum=sum+n(i)
29end if
30
31print*, 'Number=', n(i), ' SUM=', sum
32
33end do
34
35print*, 'Fibonacci number now larger than 4 million'
36
37end program fibonacci

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