Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,121 questions

55,995 answers

573 users

How to print every month between two years that contains five full weekends (Fri, Sat, Sun) in Pascal

1 Answer

0 votes
// A month has five full weekends when it has 31 days,
// and the 1st day of the month is a Friday.

program FiveFullWeekends;

{$mode objfpc}

uses
  SysUtils;

// ------------------------------------------------------------
// Month names as a single reusable constant
// ------------------------------------------------------------
const
  monthNames: array[1..12] of string = (
    'January', 'February', 'March', 'April', 'May', 'June',
    'July', 'August', 'September', 'October', 'November', 'December'
  );

// ------------------------------------------------------------
// Helper: check if a year is a leap year
// ------------------------------------------------------------
function IsLeapYear(y: Integer): Boolean;
begin
  Result := ((y mod 4 = 0) and (y mod 100 <> 0)) or (y mod 400 = 0);
end;

// ------------------------------------------------------------
// Function: returns true if a month has 5 full weekends
// ------------------------------------------------------------
function hasFiveFullWeekends(y, m: Integer): Boolean;
var
  daysInMonth: Integer;
  weekday: Integer;
begin
  // Days in each month
  case m of
    1,3,5,7,8,10,12: daysInMonth := 31;
    4,6,9,11:        daysInMonth := 30;
    2: if IsLeapYear(y) then daysInMonth := 29 else daysInMonth := 28;
  end;

  // DayOfWeek: Sunday=1, Monday=2, ..., Friday=6, Saturday=7
  weekday := DayOfWeek(EncodeDate(y, m, 1));

  Result := (daysInMonth = 31) and (weekday = 6); // Friday
end;

// ------------------------------------------------------------
// Main program
// ------------------------------------------------------------
var
  startYear, endYear, y, m: Integer;
begin
  startYear := 2026;
  endYear   := 2030;

  for y := startYear to endYear do
  begin
    Write(y, ' ');

    for m := 1 to 12 do
    begin
      if hasFiveFullWeekends(y, m) then
        Write(#10, monthNames[m], ' ', y, ' has five full weekends.');
    end;

    Writeln;
  end;
end.



(* 
run:

2026 
May 2026 has five full weekends.
2027 
January 2027 has five full weekends.
October 2027 has five full weekends.
2028 
December 2028 has five full weekends.
2029 
2030 
March 2030 has five full weekends.

*)

 



answered May 28 by avibootz

Related questions

...