关于万年历源代码的几个问题
#include <stdio.h> #include <conio.h>
#include<dos.h>
void calendar(int,int);
int leapyear(int);
int week(int,int,int);
int monthday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
struct date d;
getdate(&d);
printf("Today is %d year %d month %d day\n",d.da_year,d.da_mon,d.da_day);
calendar(d.da_year,d.da_mon-1);
system("pause");
return 0;
}
void calendar(int year,int month)
{
int d,i,s,c;
char x;
while(month>11) {
month-=12;
year++;
}
while(month<0) {
year--;
month+=12;
}
if(leapyear(year)) monthday[1]=29;
printf("%d %d\n",year,month+1);
printf("S M T W T F S\n\n");
s=week(year,month+1,1);
for(i=0; i<3*s; i++ ) printf(" ");
c=s;
for(d=1;d<=monthday[month];d++)
{
if(c>6)
{
printf("\n");
c=0;
}
c++;
printf("%d",d);
printf("%s",(d<10)?" ":" ");
}
printf("\n");
printf("nextmonth :N lastmonth :P quit :any keys. Choose: ");
x=getch();
printf("%c\n",x);
if(x=='N' || x=='n')
{
calendar(year,month+1);
}
else if(x=='P' || x=='p')
{
calendar(year,month-1);
}
else
{
printf("Thank you !\n");
return;
}
}
int leapyear(int year)
{
return ((year%4==0 && year%100!=0) || (year%4==0 && year%400==0));
}
int week(int y,int m,int d)
{
if((m==1)||(m==2))
{
m+=12;
y--;
}
return ((d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)+1)%7;
}
return ((d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)+1)%7的值返回到s=week(year,month+1,1); 中的哪个实参中?或者说应该怎么返回?
void calendar(int,int); 和int week(int,int,int); 的括号里为什么是2个和3个int?
printf("Today is %d year %d month %d day\n",d.da_year,d.da_mon,d.da_day); 中后面为什么是d.da_year,d.da_mon,d.da_day?是struct date d的固定格式吗?
s=week(year,month+1,1); 中最后一个1是什么意思?
for(d=1;d<=monthday[month];d++) 中为什么是monthday[month]?[]里面为什么是month?而不是12?
c=0; 和c++; 的作用是什么?
麻烦各位高人了~!先谢谢了!