How to resolve the algorithm Five weekends step by step in the Ada programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Five weekends step by step in the Ada programming language
Table of Contents
Problem Statement
The month of October in 2010 has five Fridays, five Saturdays, and five Sundays.
Algorithm suggestions
Extra credit Count and/or show all of the years which do not have at least one five-weekend month (there should be 29).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Five weekends step by step in the Ada programming language
Source code in the ada programming language
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar.Formatting; use Ada.Calendar;
use Ada.Calendar.Formatting;
procedure Five_Weekends is
Months : Natural := 0;
begin
for Year in Year_Number range 1901..2100 loop
for Month in Month_Number range 1..12 loop
begin
if Day_Of_Week (Formatting.Time_Of (Year, Month, 31)) = Sunday then
Put_Line (Year_Number'Image (Year) & Month_Number'Image (Month));
Months := Months + 1;
end if;
exception
when Time_Error =>
null;
end;
end loop;
end loop;
Put_Line ("Number of months:" & Integer'Image (Months));
end Five_Weekends;
You may also check:How to resolve the algorithm Knuth shuffle step by step in the REBOL programming language
You may also check:How to resolve the algorithm Prime decomposition step by step in the SPAD programming language
You may also check:How to resolve the algorithm Vigenère cipher step by step in the Objeck programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the F# programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the HolyC programming language