Search code examples
pascalfreepascalleap-year

Leap year in FreePascal


Input - Year

Output - Leap year or not

I have tried

Program LeapYear;

var  
    Year:Integer

begin

    writeln('Insert year');
    readln(Year)

    if Year MOD 4 = 0 and Year MOD 100 = 0 and not Year MOD 400 = 0 then
        begin
            writeln(Year,'is leap year')
        end
    else
        begin
            writeln(Year,'is not leap year')
        end

end.

But this is not working


Solution

  • Your algorithm is wrong. It should be:

    if (year mod 400 = 0) or ((year mod 4 = 0) and not (year mod 100 = 0))