License Public Domain
Lines 21
Permissions
Owner: ragecage
Group Owner: SnortSnort
Viewable by Everyone
Editable by All Siafoo Users
Hide
Siafoo is here to make coding less frustrating and to save you time. Join Siafoo Now or Learn More
Note: You are viewing an old version of this snippet. View Latest Version

Fibonacci problem Atom Feed 0

# '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 l,k,m,j,i,n(0:2000),nmin,nmax,capk,capn, sum
10
11n(0) = 1
12n(1) = 1
13
14sum=0
15
16do i=2,2000
17
18n(i) = n(i-1) + n(i-2)
19
20if(n(i).ge.4e6) then
21exit
22end if
23if(mod(n(i),2).eq.0) then
24sum=sum+n(i)
25end if
26
27print*, 'Number=', n(i), ' SUM=', sum
28
29end do
30
31print*, 'Fibonacci number now larger than 4 million'
32
33end program fibonacci