>>815 �A
% Prolog

t815_2 :-
  user_parameters([_年,_月]),
  月末日(_年,_月,_月末日),
  write_formatted('%t年%月の月末日は%t日です\n',[_年,_月,_月末日]).

月末日(_年,2,29) :-
  atom_to_term(_年,_年整数,_),
  うるう年(_年整数),!.
月末日(_年,2,28).
月末日(_年,_月,30) :-
  member(_月,['4','6','9','11']).
月末日(_年,_月,31) :-
  member(_月,['1','3','5','7','8','10','12']).

うるう年(_年) :- 0 is _年 mod 400,!.
うるう年(_年) :- 0 is _年 mod 100,!,fail.
うるう年(_年) :- 0 is _年 mod 4,!.
うるう年(_年) :- not(0 is _年 mod 4),fail.