万年历查询程序
【万年历的C语言程序】
已经编译运行确认过。
#include<stdio.h>
#include<stdlib.h>
intleap(int);/*判断是否为闰年*/
intmd(intm,inty);/*返回本月的天数*/
voidprtweek(void);/*输出表头*/
intfw(intm,inty);/*返回本月一号是星期几*/
voidprtmonth(intm);/*输出月份表头*/
intmain(void)
{
inty,m,i,test,week;
printf("请输入您要查询的年份:");
scanf("%d",&y);
for(m=1;m<=12;m++){
test=1;
prtmonth(m);
prtweek();
week=fw(m,y);
if(week!=6)
for(i=0;i<=week;i++){
putchar('t');
test++;
}
for(i=1;i<=md(m,y);i++,test++){
printf("%dt",i);
if(test%7==0){
putchar('n');
}
}
putchar('n');
system("pause");//暂停,以便观察输出
}
return0;
}
intleap(inty)
{
return(y%4==0&&y%100||y%400==0)?1:0;
}
intmd(intm,inty)
{
intd;
switch(m){
case1:
case3:
case5:
case7:
case8:
case10:
case12:d=31;break;
case4:
case6:
case9:
case11:d=30;break;
case2:d=leap(y)?29:28;break;
}
returnd;
}
voidprtweek(void)
{
printf("%st%st%st%st%st%st%stn","Sun","Mon","Tue","Wed","Thur","Fri","Sat");
}
intfw(intm,inty)
{
intf;
if(m<3){
m+=12;
y--;
}
f=(1+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
returnf;
}
voidprtmonth(intm)
{
switch(m){
default:
case1:puts("===January===");break;
case2:puts("===February===");break;
case3:puts("===March===");break;
case4:puts("===April===");break;
case5:puts("===May===");break;
case6:puts("===June===");break;
case7:puts("===July===");break;
case8:puts("===August===");break;
case9:puts("===September===");break;
case10:puts("===October===");break;
case11:puts("===November===");break;
case12:puts("===December===");break;
}
}
万年历查询程序相关文章: