Fortran Implementation of Problem 1

View source code here on GitHub!

integer Problem0001/p0001()
 1! Project Euler Question 1
 2!
 3! I did it the old-fashioned way in this language
 4!
 5! Problem:
 6!
 7! If we list all the natural numbers below 10 that are multiples of 3 or 5, we
 8! get 3, 5, 6 and 9. The sum of these multiples is 23.
 9!
10! Find the sum of all the multiples of 3 or 5 below 1000.
11
12module Problem0001
13    implicit none
14contains
15    pure integer function p0001() result(answer)
16        integer :: i
17        answer = 0
18
19        do i = 3, 999, 3
20            answer = answer + i
21        end do
22
23        do i = 5, 999, 5
24            answer = answer + i
25        end do
26
27        do i = 15, 999, 15
28            answer = answer - i
29        end do
30    end function p0001
31end module Problem0001

Tags: divisibility