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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/** * @copyright 2011 Chunhui Wang
*
* wangchunhui@wangchunhui.cn
*/ #include<stdio.h> int main()
{ printf ( "\t\t\t万年历\n" );
printf ( "\t\t\t\t------Made by Chunhui Wang\n\n" );
int
i,year, month;
int
day; //记录每月第一天是周几。
int
date; //每年星期变化,平年加1,闰年加2。
int
a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; //月份天数 。
int
Year[10000]; //每年第一天周几。
Year[1900]=1;
for (i=1900;i<9999;i++)
{
date=1;
if ((i%4==0)&&(i%100!=0)||(i%400==0))
{
date=2;
}
Year[i+1]=(Year[i]+date)%7;
}
while (1)
{
printf ( "请输入年份(如1900):" );
scanf ( "%d" ,&year);
printf ( "请输入月份(如 01):" );
scanf ( "%d" ,&month);
a[2]=28;
if (((year%4==0)&&(year%100!=0)||(year%400==0))&&(month>=2))
{
a[2]=29;
}
day=Year[year];
for (i=1;i<month;i++)
{
day=day+a[i];
}
day=day%7;
printf ( "\t\t\t\t%d年%d月份\n\n" ,year,month);
printf ( "\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期日\n" );
for (i=0;i<day;i++)
{
printf ( "\t" );
}
if (day==0) printf ( "\t\t\t\t\t\t\t" );
for (i=0;i<a[month];i++)
{
printf ( "%d\t" ,i+1);
if ((i+day)%7==0)
{
printf ( "\n\t" );
}
}
printf ( "\n\n\n\n" );
}
return
0;
} |