% leap_year.m
% Determine if the year Y is a leap year or not.
%
%  Is Y a leap year?
%
%  YES, if Y divisible by 4
%  BUT if Y is also divisible by 100, it's not,
%  BUT if Y is also divisible by 400, it is.
%
%  The MATLAB function
%    a = mod ( b, c )
%  returns in A the remainder after B is divided by C.
%  If A is zero, then B is divisible by C.
%
%  MATLAB includes two special constants, "true" and "false".
%
y = input ( '  Enter the year to check: ' );

if ( mod ( y, 4 ) == 0 )
  leap = true;
else
  leap = false;
end
%
%  "Change your mind" if Y is divisible by 100.
%
if ( mod ( y, 100 ) == 0 )
  leap = false;
end
%
%  "Change your mind again" if Y is divisible by 1600.
%
if ( mod ( y, 1600 ) == 0 )
  leap = true;
end
%
%  Report your decision.
%
if ( leap )
  fprintf ( '  The year %d is a leap year.\n', y );
else
  fprintf ( '  The year %d is NOT a leap year.\n', y );
end
