Fortran - gregorymorrison/euler1 GitHub Wiki

Does anyone still use Fortran anymore? This language was introduced in 1957, and I decided to kick its tires on a lark. Writing this version of Euler1 was my first excursion into Fortran, and I hope it will be my last. One problem is that there are multiple incompatible standards - expect a lot of confusion and conflicting statements. Also, the type system is super-explicit - it's difficult to make it happy. I shouldn't dismiss this so readily, though, since this language has had a tremendous amount of modernization. And this compiler and executable felt screamingly fast.

After maybe three hours of frustration I was able to turn out this version of Euler1:

! Euler1 in Fortran90

program euler1
    integer :: euler

    print*, euler(999)
end

function euler(size)
    integer euler, size
    euler = 0

    do i = 0, size
        if (modulo(i,3)==0 .or. modulo(i,5)==0) then
             euler = euler + i
        end if
 end do
end

I used gfortran for this exercise. To run this code, compile and execute as below:

$ gfortran -ffree-form euler1.f -o euler1.out
$ ./euler1.out
 233168