回 帖 发 新 帖 刷新版面

主题: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

回复列表 (共2个回复)

沙发

你怎么copy我的字啊? (^_^)

程序不是已经贴出来了吗?就是不要用到函数是吗?现在晚上一点半噢,修改好的程序有没有错你自己测试啦!


program calendar;
Const
   mdays:array[1..12] of integer=(31,28,31,30,31,30,31,31,30,31,30,31);
var
   year,month,m,n,i:integer;

begin
    write('Enter year , month: ');
    readln(year,month);
    m:=(year+(year-1) div 4-(year-1) div 100+(year-1) div 400) mod 7;
                                            {m = 该年第一天星期几}

    for i:=1 to month-1 do
     begin
       m := m+mdays[i];
       if (i=2) and ((year mod 4=0) and (year mod 100<>0) or (year mod 400=0))
          then m := m+1;
     end;
    m:=m mod 7;       {m = 该月第一天星期几}

    writeln;
    writeln(year,'-',month);
    writeln('SUN':6,'MON':6,'TUE':6,'WED':6,'THU':6,'FRI':6,'SAT':6);
    for i:=0 to m-1 do write(' ':6);
    n:=mdays[month];
    if (month=2) and ((year mod 4=0) and (year mod 100<>0) or (year mod 400=0))
       then n:=n+1;                {n = 该月的天数}

    for i:=1 to n do
      begin
          write(i:6);
          m:=m+1;
          if m mod 7=0 then writeln;
      end;
     writeln;
end.

板凳

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.
我这样做对不对呢
如不对
应怎样修改??
我发现了当我输入1月的时候
便有问题了..没有任何日期出现
为什麽呢?应该怎样修改
请帮帮忙...

我来回复

您尚未登录,请登录后再回复。点此登录或注册