MATLAB 闰年判断与闰年输出


代码

下列代码仅供参考

%RunNian1900-2016_ezhq
function leapyear
for year = 1900:2016
  sign = 0;
  a = rem(year,400);
  b = rem(year,4);
  c = rem(year,100);
  if a == 0
    sign = sign + 1;
  end
  if b == 0
    sign = sign + 1;
  end
  if c == 0
    sign = sign - 1;
  end
  if sign == 1
    fprintf('%4d \n',year)
  end
end

运行结果

运行结果截图
运行结果截图


Author: ezhq
Reprint policy: All articles in this blog are used except for special statements CC BY-NC-SA 4.0 reprint polocy. If reproduced, please indicate source ezhq !
Pay
  TOC