Last Friday of each month: Difference between revisions

Content added Content deleted
(Add Seed7 example)
(adding fortran)
Line 292: Line 292:
2012-Nov-30
2012-Nov-30
2012-Dec-28</pre>
2012-Dec-28</pre>

=={{header|Fortran}}==

Algorithm: compute day of week for last day of month, then subtract just enough to get to the preceding friday. Do this for each month. To simplify computations further, we only need to compute day of week of january 1st (the others are found by adding month lengths). Since day of week need only be known modulo 7, we do not compute modulo at all except once when subtracting.
<lang fortran>program fridays
integer :: days(1:12) = (/31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/)
integer :: year, k, y
read *, year
if (mod(year, 400) == 0 .or. (mod(year, 4) == 0 .and. mod(year, 100) /= 0)) days(2) = 29
y = year - 1
k = 41 + y + y/4 + 6*(y/100) + y/400
do m = 1, 12
k = k + days(m)
print "(I4,A1,I2.2,A1,I2)", year, '-', m, '-', days(m) - mod(k + 3, 7)
end do
end program</lang>



=={{header|Go}}==
=={{header|Go}}==