I was solving Project Euler problems using Fortran; the problem is to create a Fibonacci sequence and find the sum of all even numbers that come under 4 million. Here's what I wrote
implicit none
integer*4::a(1:4000000),sum
integer*4::i,maxc
maxc = 3999999
a(1) = 1
a(2) = 2
do i = 3,maxc,1
a(i) = a(i-1) + a(i-2)
end do
sum = 0
do i = 1,maxc
if (mod(a(i),2)==0) then
sum = sum + a(i)
end if
end do
print*,sum
end
The output is -1833689714
Any idea what went wrong?