1. 请问写一个日历的C语言程序,代码怎么写

||

#include<conio.h>
#include<stdio.h>
#include<time.h>
#include<stdlib.h>

constmonthDay[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
intisLeap(intyear)
{
if(year%4)return0;
if(year%400)return1;
if(year%100)return0;
return1;
}
intgetWeek(intyear,intmonth,intday)
{
intc,y,week;
if(month==1||month==2)//判断month是否为1或2
{
year--;
month+=12;
}
c=year/100;
y=year-c*100;
week=(c/4)-2*c+(y+y/4)+(13*(month+1)/5)+day-1;
while(week<0){week+=7;}
week%=7;
returnweek;
}

voiddisplay(intyear,intmonth)
{
intmonthDays,weekFirst,i;
monthDays=monthDay[month]+(month==2?isLeap(year):0);
weekFirst=getWeek(year,month,1);
system("cls");
printf("-------%4d年----%2d月------- ",year,month);
printf("星期日星期一星期二星期三星期四星期五星期六 ");
for(i=0;i<weekFirst;i++)printf("");
for(i=1;i<=monthDays;i++)
{
printf("%8d",i);
weekFirst++;
if(weekFirst>=7){printf(" ");weekFirst=0;}
}
}
voidmain()
{
intyear,month,chr;
time_ttimer;
structtm*tblock;
timer=time(NULL);
tblock=localtime(&timer);
year=tblock->tm_year+1900;
month=tblock->tm_mon+1;
while(1)
{
display(year,month);
chr=getch();
if(chr==0xe0)
{
chr=getch();
if(chr==0x4b)/*方向键(←)*/
{
month--;
if(month<1){month=12;year--;}
}
elseif(chr==0x4d)/*方向键(→)*/
{
month++;
if(month>12){month=1;year++;}
}
}
elseif(chr=='q'||chr=='Q')break;
}
}