已知公元1年1月1日是星期一。任意输入一个年份和月份(公元1年1月以后),输出该月的日历表。用PASCAL语言

2020-05-15 教育 172阅读
这个是输入年月日,还有一些附加的东西的。。。应该没事。。。
Program day;
Label
1,2,3;
Const
dt: Array[0..6] OF string = ('周日', '周一', '周二', '周三', '周四', '周五', '周六');
Var
date, year, month: integer;
i,j,k,m,n:integer;
a:array[0..47] of integer;
c:char;
m1,m2:integer;
procedure line();
var
i:integer;
begin
for i:=1 to 40 do write('*');
writeln;
end;
Function year1(year, month, day: longint): Longint;
Var
sum, i: longint;
Begin
sum := 0;
for i:=1 TO month-1 Do
Begin
if i in [1, 3, 5, 7, 8, 10, 12] Then sum := sum + 31;
if i in [4, 6, 9, 11] Then sum := sum + 30;
if i = 2 Then Begin
if ((year mod 4 = 0) And (year mod 100 <> 0)) Or (year mod 400 = 0) Then sum := sum + 29 Else sum := sum + 28;
End;
End;
year1 := sum + day;
End;
Function week(year, month, day: longint): longint;
Begin
week := (((year - 1) + (year - 1) div 4 - (year - 1) Div 100 + (year - 1) Div 400) + year1(year, month, day)) Mod 7;
End;
procedure calendar(var month:integer);
begin
if (month=0) then begin year:=year-1; month:=12; end;
if (month=13) then begin year:=year+1; month:=1; end;
line();
writeln(year:12,'年',month,'的月历');
writeln;
write (' 日 一 二 三 四 五 六');
k:=date;
m:=week(year,month,1);
for i:=0 to m-1 do
a[i]:=32;
case month of
1,3,5,7,8,10,12: n:=m+30;
4,6,9,11: n:=m+29;
2: if ((year mod 4 = 0) And (year mod 100 <> 0)) Or (year mod 400 = 0)
Then n:=m+28 Else n:=m+27;
end;
for i:=m to n do
a[i]:=i-m+1;
for i:=n+1 to 47 do
a[i]:=32;
writeln;
for i:=0 to m-1 do
write (chr(a[i]):4);
for i:=m to n do
begin
write (a[i]:4);
if (i+1) mod 7=0 then writeln;
end;
for i:=n+1 to 47 do
begin
write (chr(a[i]):4);
if i mod 7=0 then writeln;
end;
writeln;
line();
end;
Begin
1:Writeln('输入 年份 ');
Readln(year);
Writeln('输入 月份 ');
Readln(month);
Writeln('输入 日期 ');
Readln(date);
Writeln(year,'-',month,'-',date,'是',dt[week(year, month, date)]);
calendar(month);
2: writeln (' 输入Y重来');
writeln (' 输入N,查看下一个月月历');
writeln (' 输入L,查看上一个月月历');
writeln (' 输入其他字符退出');
line();
readln(c);
if c='y' then goto 1;
if c='Y' then goto 1;
if ((c='n') or (c='N')) then begin month:=month+1;calendar(month);end;
if ((c='l') or (c='L')) then begin month:=month-1;calendar(month); end;
if ((c<>'y')and(c<>'Y')and(c<>'n')and(c<>'N')and(c<>'l')and(c<>'L')) then goto 3;
goto 2;
3:
End.
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com