主题:PASCAL高手们,救救我这只菜鸟吧!
输入年,月,打印出当月月历。比如:输入2005 4 打印出当月月历:
2005-4
SUN MON TUE WED THU FRI SAT
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
怎樣能做到呢?
我想到头也快爆了
若果一定要用这条方程式
y=year-1
first day=(36+y+(y div 4)-(y div 100)+(y div 400)mod7
及只可以用if..case...while do...for to do...repeat-until等基本指令
能做到嗎??
我这样做对不对呢
如不对
应怎样修改??
我发现了当我输入1月的时候
便有问题了..没有任何日期出现
为什麽呢?应该怎样修改
请帮帮忙...
program prog;
uses wincrt;
var
year,month:integer;
m,n,i:integer;
first_day,daysNum:integer;
procedure get_week(year:integer;var first_day:integer);
var
x:integer;
y:integer;
begin
y:=year-1;
x:=year+(y) div 4 -(y) div 100 + (y) div 400;
first_day:=x mod 7;
end;
procedure getdaysNum(year,month:integer;var daysNum,i:integer);
var
x:integer;
begin
case month of
1,3,5,7,8,10,12: x:=31;
2: if year mod 4=0 then x:=29
else x:=28;
4,6,9,11: x:=30;
end;
daysNum:=x;
end;
begin
writeln('welcome');
readln;
write('Enter the month and year required: ');
readln(month,year);
get_week(year,first_day);
m:=first_day;
for i:=1 to month-1 do
getdaysNum(year,month,daysNum,i);
n:=n+daysNum;
m:=(m+n) mod 7;
writeln;
writeln(month,' ',year);
writeln('SUN':6,'MON':6,'TUE':6,'WED':6,'THU':6,'FRI':6,'SAT':6);
for i:=0 to m-1 do write(' ':6);
getdaysNum(year,month,daysnum,i);
for i:=1 to n do
begin
write(i:6);
m:=m+1;
if m mod 7=0 then writeln;
end;
writeln;
end.
也想問一下為什為用以下的句子
if m mod 7=0 then writeln
2005-4
SUN MON TUE WED THU FRI SAT
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
怎樣能做到呢?
我想到头也快爆了
若果一定要用这条方程式
y=year-1
first day=(36+y+(y div 4)-(y div 100)+(y div 400)mod7
及只可以用if..case...while do...for to do...repeat-until等基本指令
能做到嗎??
我这样做对不对呢
如不对
应怎样修改??
我发现了当我输入1月的时候
便有问题了..没有任何日期出现
为什麽呢?应该怎样修改
请帮帮忙...
program prog;
uses wincrt;
var
year,month:integer;
m,n,i:integer;
first_day,daysNum:integer;
procedure get_week(year:integer;var first_day:integer);
var
x:integer;
y:integer;
begin
y:=year-1;
x:=year+(y) div 4 -(y) div 100 + (y) div 400;
first_day:=x mod 7;
end;
procedure getdaysNum(year,month:integer;var daysNum,i:integer);
var
x:integer;
begin
case month of
1,3,5,7,8,10,12: x:=31;
2: if year mod 4=0 then x:=29
else x:=28;
4,6,9,11: x:=30;
end;
daysNum:=x;
end;
begin
writeln('welcome');
readln;
write('Enter the month and year required: ');
readln(month,year);
get_week(year,first_day);
m:=first_day;
for i:=1 to month-1 do
getdaysNum(year,month,daysNum,i);
n:=n+daysNum;
m:=(m+n) mod 7;
writeln;
writeln(month,' ',year);
writeln('SUN':6,'MON':6,'TUE':6,'WED':6,'THU':6,'FRI':6,'SAT':6);
for i:=0 to m-1 do write(' ':6);
getdaysNum(year,month,daysnum,i);
for i:=1 to n do
begin
write(i:6);
m:=m+1;
if m mod 7=0 then writeln;
end;
writeln;
end.
也想問一下為什為用以下的句子
if m mod 7=0 then writeln