Pascal一問 高手入

2008-10-17 2:02 am
A leap year is a year that is divisible by 4 except that it is divisible by 100. Howerever, if it is divisible by 400, it is still a leap year. Write a program get the year no. and determine it is a leap year or not.

Sample Output:
Enter a year: 2000
It is a leap year.

program Leap Year;
var
year : integer;
leap : boolean;
接住寫落去

thx!
急急急急急

回答 (1)

2008-10-17 4:28 am
✔ 最佳答案
program Leap_Year;
var
year : integer;
leap : boolean;
begin
writeln('Enter a year:');
readln(year);
if (year mod 4 = 1) or (year mod 4 = 2) or (year mod 4 = 3) or (year mod 100 = 0) and not (year mod 400 = 0)
then leap:=false
else if (year mod 4 = 0) or (year mod 400 = 0)
then leap:=true;
if (leap=true)
then writeln('It is a leap year!')
else writeln('It is not a leap year!');
readln;
end.

ps. 其實唔洗要leap: boolean 都得,可以直接o係if then else 度加writeln...


收錄日期: 2021-04-13 16:10:39
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20081016000051KK01166

檢視 Wayback Machine 備份