#include
voidDateTrans(char*chDate,int*nYear,int*nMonth,int*nDay);
//1
intIsLeapYear(intnYear);
//2
intGetWeekOfFirstday(intnYear);
//3
intGetWeek(intnYear,intnMonth,intnDay,intnWeekOfFirstday);
//4
voidPrintCalendar(intnWeek,intnDay,intnMonthDays,char*chDate);
//5
voidDateTrans(char*chDate,int*nYear,int*nMonth,int*nDay)
//1
{
*nYear=(chDate[0]-'0')*1000+(chDate[1]-'0')*100+(chDate[2]-'0')*10+chDate[3]
-'0';
*nMonth=(chDate[5]-'0')*10+chDate[6]-'0';
*nDay=(chDate[8]-'0')*10+chDate[9]-'0';
}
intIsLeapYear(intnYear)
//2
{
if(nYear%4==0)
return1;
el
return0;
}
intGetWeekOfFirstday(intnYear)
//3
{
if(nYear>2000)
return((nYear-2001)*365+(nYear-2001)/4+1)%7;
elif(nYear<2000)
return6-((2000-nYear)*365+(2000-nYear)/4)%7;
el
return6;
}
intGetWeek(intnYear,intnMonth,intnDay,intnWeekOfFirstday)
//4
{
intnDaysYear[]={31,28,31,30,31,30,31,31,30,31,30,31};
intnDaysLeapYear[]={31,29,31,30,31,30,31,31,30,31,30,31};
inti,sum=0;
if(nYear%4==0)
{
for(i=0;i<(nMonth-1);i++)
{
sum+=nDaysLeapYear[i];
}
return(sum+nDay+nWeekOfFirstday-1)%7;
}
el
{
for(i=0;i<(nMonth-1);i++)
{
sum+=nDaysYear[i];
}
return(sum+nDay+nWeekOfFirstday-1)%7;
}
}
voidPrintCalendar(intnWeek,intnDay,intnMonthDays,char*chDate)
//5
{
inti,j;
printf("thecalenderofthismonthasfollowing:n");
printf("*********************************n");
printf("SUNMONTUEWENTHUFRISTAn");
for(i=1,j=1;j<=nMonthDays;i++)
{
if(i<=nWeek+1)
printf("");
el
{
printf("%4d",j);
j++;
}
if(i%7==0)
printf("n");
}
printf("n********************************n");
printf("OK!n");
}
main()
{
charchDate[11],i=0,j,isleapyear;
intnYear,nMonth,nDay;
intnWeekOfFirstday;
intnMonthDays;
intnWeek;
char*Week;
intnDaysYear[]={31,28,31,30,31,30,31,31,30,31,30,31};
intnDaysLeapYear[]={31,29,31,30,31,30,31,31,30,31,30,31};
printf("请输入你要查找的日期,如(20010101或2001.01.01:n或者是你
想要日历的月份:如(200001或2000.01):n");
do{
scanf("%c",&chDate[i]);
i++;
}while(chDate[i-1]!='n');
if(i==11)
chDate[i-1]='0';
el
for(j=8;j<11;j++)
chDate[j]='0';
DateTrans(chDate,&nYear,&nMonth,&nDay);
//1
while(nYear<=0||nMonth<1||nMonth>12)
{
printf("查询年月chDate非法n");
return0;
}
nWeekOfFirstday=GetWeekOfFirstday(nYear);
//3
nWeek=GetWeek(nYear,nMonth,nDay,nWeekOfFirstday);
//4
isleapyear=IsLeapYear(nYear);
//2
if(isleapyear==1)
nMonthDays=nDaysLeapYear[nMonth-1];
elif(isleapyear==0)
nMonthDays=nDaysYear[nMonth-1];
if(i==11)
{
while(nDay<1||nDay>nMonthDays)
{
printf("查询日期chDate非法n");
return0;
}
switch(nWeek)
{
ca0:
Week="SUNDAY";
break;
ca1:
Week="MONDAY";
break;
ca2:
Week="TUESDAY";
break;
ca3:
Week="WEDNESDAY";
break;
ca4:
Week="THUESDAY";
break;
ca5:
Week="FRIDAY";
break;
ca6:
Week="SATERDAY";
break;
}
printf("Thisday(%s)is%sn",chDate,Week);
printf("OK!n");
}
el
PrintCalendar(nWeek,nDay,nMonthDays,chDate);//5
}
本文发布于:2022-11-25 12:35:28,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/90/18498.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |