Jump to content

Day of the week: Difference between revisions

m
Fixed tags
m (Fixed tags)
Line 270:
{{works with|Fortran|90 and later}}
Based on Forth example
<lang fortran>PROGRAM YULETIDE
IMPLICIT NONE
INTEGER :: day, year
WRITE(*, "(A)", ADVANCE="NO") "25th of December is a Sunday in"
DO year = 2008, 2121
day = Day_of_week(25, 12, year)
IF (day == 1) WRITE(*, "(I5)", ADVANCE="NO") year
END DO
CONTAINS
FUNCTION Day_of_week(d, m, y)
INTEGER :: Day_of_week, j, k
INTEGER, INTENT(IN) :: d, m, y
j = y / 100
k = MOD(y, 100)
Day_of_week = MOD(d + (m+1)*26/10 + k + k/4 + j/4 + 5*j, 7)
END FUNCTION Day_of_week
END PROGRAM YULETIDE</lang>
Output
25th of December is a Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
Line 313:
=={{header|Haskell}}==
Using the time library:
<lang haskell>import Data.Time
<pre>
import Data.Time
import Data.Time.Calendar.WeekDate
 
Line 321 ⟶ 320:
 
main = mapM_ putStrLn ["25 December " ++ show year ++ " is Sunday"
| year <- [2008..2121], isXmasSunday year]</lang>
</pre>
Output:
<pre>
Line 345 ⟶ 343:
 
The built-in System.Time module overflows at the Unix epoch in 2038:
<lang haskell>import System.Time
<pre>
import System.Time
 
isXmasSunday year = ctWDay cal == Sunday
Line 366 ⟶ 363:
 
main = mapM_ putStrLn ["25 December " ++ show year ++ " is Sunday"
| year <- [2008..2121], isXmasSunday year]</lang>
</pre>
Output on 32-bit machine:
<pre>
Line 424 ⟶ 420:
Consequently, it suffers from the same problem as C.
 
<lang modula3>MODULE Yule EXPORTS Main;
<pre>
MODULE Yule EXPORTS Main;
 
IMPORT IO, Fmt, Date, Time;
Line 452 ⟶ 447:
END;
END;
END Yule.</lang>
</pre>
 
Output:
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.