Fibonacci problem  Fortran
Revision 3 vs. Revision 4
Legend:
 Unmodified
 Added
 Removed

Code
r3 r4 3 3 4 4 5 5 program fibonacci 6 6 7 7 implicit none 8 ! Define the single and double precisionvariables.8 ! Define the variables. 9 9 integer i,n(0:2000),sum 10 10 11 12 13 ! Initialize the Fibonacci Sequence. 11 14 n(0) = 1 12 15 n(1) = 1 13 14 16 ! Initialize the Sum. 15 17 sum=0 18 ! Supply the first two lines of output. 16 19 print*, 'Number=', n(0), ' SUM=', sum 17 20 print*, 'Number=', n(1), ' SUM=', sum 18 21 19 22 do i=2,2000 20 23 ! Define the next number in the sequence. 21 24 n(i) = n(i1) + n(i2) 22 25 ! Exit the loop if the latest number is greater than 4 million. 23 26 if(n(i).ge.4e6) then 24 27 exit 25 28 end if 26 29 ! Only add the latest number if it is even. 27 30 if(mod(n(i),2).eq.0) then 28 31 sum=sum+n(i) 29 32 end if 30 33 ! Print out the latest fibonacci number and the sum. 31 34 print*, 'Number=', n(i), ' SUM=', sum 32 35 33 36 end do 34 37 35 38 print*, 'Fibonacci number now larger than 4 million'