Day of the week of Christmas and New Year: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add COBOL) |
Not a robot (talk | contribs) (Add Cowgol) |
||
Line 294: | Line 294: | ||
<pre>25/12/2021 is a Saturday |
<pre>25/12/2021 is a Saturday |
||
01/01/2022 is a Saturday</pre> |
01/01/2022 is a Saturday</pre> |
||
=={{header|Cowgol}}== |
|||
<lang cowgol>include "cowgol.coh"; |
|||
record Date is |
|||
year: uint16; |
|||
month: uint8; |
|||
day: uint8; |
|||
end record; |
|||
sub DayName(date: [Date]): (name: [uint8]) is |
|||
var days: [uint8][] := { |
|||
"Saturday", "Sunday", "Monday", "Tuesday", |
|||
"Wednesday", "Thursday", "Friday" |
|||
}; |
|||
var m := date.month as uint16; |
|||
var y := date.year; |
|||
var d := date.day as uint16; |
|||
if m <= 2 then |
|||
m := m + 12; |
|||
y := y - 1; |
|||
end if; |
|||
var j := y / 100; |
|||
var k := y % 100; |
|||
d := (d + ((m+1)*26)/10 + k + k/4 + j/4 + 5*j) % 7; |
|||
name := days[d as @indexof days]; |
|||
end sub; |
|||
sub printDate(date: [Date]) is |
|||
print_i8(date.month); |
|||
print_char('/'); |
|||
print_i8(date.day); |
|||
print_char('/'); |
|||
print_i16(date.year); |
|||
end sub; |
|||
var dates: Date[] := { |
|||
{2021, 25, 12}, |
|||
{2022, 1, 1} |
|||
}; |
|||
var i: @indexof dates := 0; |
|||
while i < @sizeof dates loop |
|||
printDate(&dates[i]); |
|||
print(" is a "); |
|||
print(DayName(&dates[i])); |
|||
print_nl(); |
|||
i := i + 1; |
|||
end loop;</lang> |
|||
{{out}} |
|||
<pre>25/12/2021 is a Saturday |
|||
1/1/2022 is a Saturday</pre> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |