diff --git a/年历显示(修改).c b/年历显示(修改).c new file mode 100644 index 0000000..a6a9875 --- /dev/null +++ b/年历显示(修改).c @@ -0,0 +1,333 @@ +#include +#include +void menu(); +void year_calendar(); +void year_month_calendar(); +void year_month_day_calendar(); +int main() +{ +int choice; +menu(); +printf("ÇëÑ¡ÔñÄãÒªµÄÈÕÀú·þÎñ£º"); +scanf("%d",&choice); +switch(choice) +{ +case 1:year_calendar();break ; +case 2:year_month_calendar();break; +case 3:year_month_day_calendar();break; +} + +return 0; +} + + + +void menu() +{ +printf("\n-------------------------------------------------------\n"); +printf(" »¶Ó­À´µ½ÈÕÀú²éѯϵͳ \n"); +printf(" 1:²éѯijÄêÈÕÀú \n"); +printf(" 2:²éѯijÄêijÔµÄÈÕÀú \n"); +printf(" 3:²éѯijÄêÔÂÈÕµÄÈÕÀúÐÅÏ¢ \n"); +printf(" 4:Í˳ö \n"); +printf("-------------------------------------------------------\n"); +} + + +void year_calendar() +{ +int year,day,i,j,k,n,m,q,month_one_weekday[13];//day--µ½½ñÄêÒ»ÔÂÒ»ÈÕÇ°¹²¶àÉÙÌ죻 month_one_weekday[13]--ÿ¸öÔÂ1ºÅÊÇÐÇÆÚ¼¸£» +int month_day[13]; //month_day[13]---²éѯµ±ÄêÿÔ¹²¼Æ¶àÉÙÌì¡£ +printf("ÇëÊäÈëÄãÒª²éѯÈÕÀúµÄÄê·Ý£º"); +scanf("%d",&year); +day=0; +for(i=1;i<=year-1;i++) +{ +if( year%400==0 || (year%4==0&&year%100!=0) ) +n=366; +else n=365; +day=day+n; +} +month_day[0]=0; +for(i=1;i<=12;i++) +{ +switch(i) +{ +case 1:case 3:case 5:case 7: +case 8:case 10:case 12: month_day[i]=31;break; +case 4:case 6:case 9:case 11: month_day[i]=30;break; +case 2:if( year%400==0 || (year%4==0&&year%100!=0) ) +month_day[i]=29; +else month_day[i]=28; +break; +} +day=day+month_day[i-1]; +if((day+1)%7==0) +month_one_weekday[i]=7; +else month_one_weekday[i]=(day+1)%7;//month_one_weekday[i]:µÚi¸öÔµĵÚÒ»ÌìÊÇÐÇÆÚ¼¸ + + +} +for(i=1;i<=12;i++)//ÿѭ»·Ò»´ÎÊä³öÒ»¸öÔµÄÈÕÀú +{ +printf("\n\n"); +printf("\n%2iÔÂ\n\tSun\tMon\tTue\tWed\tThur\tFri\tSat\n",i); +for(j=1,m=0;j<=month_day[i];j++)//j:ÿ¸öÔµÄÿһÌ죻 ?m£ºÒѾ­Êä³öµÄÌìÊý +{ + + +if(j==1) +{ + +q=month_one_weekday[i]-1; +for(k=1;k<=q;k++) +printf("\t"); +printf("\t%d\t",j);m=q+1; +} +else { printf("%d\t",j);m++;} +if(m%7==0) +printf("\n\t "); +} + +} +printf("\n"); +main(); +} + + +void year_month_calendar() +{ +int year,month,day=0; +int i,j,k,n,m,q; +int month_day[13],month_one_weekday[13]; +printf("\nÇëÊäÈëÒª²éѯÈÕÀúµÄÄêÔ£º"); +scanf("%d%d",&year,&month); +day=0; +for(i=1;i<=year-1;i++) +{ +if( year%400==0 || (year%4==0&&year%100!=0) ) +n=366; +else n=365; +day=day+n; +} +month_day[0]=0; +for(i=1;i<=12;i++) +{ +switch(i) +{ +case 1:case 3:case 5:case 7: +case 8:case 10:case 12: month_day[i]=31;break; +case 4:case 6:case 9:case 11: month_day[i]=30;break; +case 2:if( year%400==0 || (year%4==0&&year%100!=0) ) +month_day[i]=29; +else month_day[i]=28; +break; +} +day=day+month_day[i-1]; +if((day+1)%7==0) month_one_weekday[i]=7; +else month_one_weekday[i]=(day+1)%7;//month_one_weekday[i]:µÚi¸öÔµĵÚÒ»ÌìÊÇÐÇÆÚ¼¸ +} +printf("%dÄêµÄµÚ%dÔÂÈÕÀúÊÇ:\n",year,month); +printf("Òª²éѯµÄµ±Ô¹²¼Æ¶àÉÙÌ죺%d\n",month_day[month]); +printf("\n%2iÔ£ºSun\tMon\tTue\tWed\tThur\tFri\tSat\n",month); +for(j=1,m=0;j<=month_day[month];j++)//j:ÿ¸öÔµÄÿһÌ죻 ?m£ºÒѾ­Êä³öµÄÌìÊý +{ +if(j==1) +{ + +q=month_one_weekday[month]-1; +for(k=1;k<=q;k++) +printf("\t"); +printf("\t%d\t",j);m=q+1; +} +else { printf("%d\t",j);m++;} +if(m%7==0) +printf("\n\t"); +} +printf("\n"); +main(); +} + + + + +void year_month_day_calendar() +{ +int year,month,dayy,day,day1,day2,weekday,flag,n1,n2,n,i;//n--¾àÀë½ñÌ컹ÓжàÉÙÌ죬dayy--ÊäÈëµÄday +int month_day[13]; +struct tm *local; +time_t t; +printf("\nÇëÊäÈë²éѯµÄÄêÔÂÈÕ£º"); +scanf("%d%d%d",&year,&month,&dayy); +printf("ÊäÈëµÄÈÕÆÚÊÇ£º%dÄê%dÔÂ%dÈÕ£¡",year,month,dayy); +if(month==1) + { + if(dayy==1) + printf("Ôªµ©"); + } + else if(month==2) + { + if(dayy==14) + printf("ÇéÈ˽Ú"); + } + else if(month==3) + { + switch(dayy) + { + case 8:printf("¸¾Å®½Ú");break; + case 12:printf("Ö²Ê÷½Ú");break; + } + } + else if(month==4) + { + if(dayy==1) + printf("ÓÞÈ˽Ú"); + } + else if(month==5) + { + switch(dayy) + { + case 1:printf("ÀͶ¯½Ú");break; + case 4:printf("ÇàÄê½Ú");break; + } + } + else if(month==6) + { + if(dayy==1) + printf("¶ùͯ½Ú"); + } + else if(month==7) + { + if(dayy==1) + printf("½¨µ³½Ú"); + } + else if(month==8) + { + if(dayy==1) + printf("½¨¾ü½Ú"); + } + else if(month==9) + { + if(dayy==10) + printf("½Ìʦ½Ú"); + } + else if(month==10) + { + if(dayy==1) + printf("¹úÇì½Ú"); + } + else if(month==11) + { + ; + } + else + { + if(dayy==25) + printf("Ê¥µ®½Ú"); + } +day=0; +for(i=1;i<=year-1;i++) +{ +if( year%400==0 || (year%4==0&&year%100!=0) ) +n=366; +else n=365; +day=day+n; +} +day1=day; +month_day[0]=0; +for(i=1;i<=12;i++) +{ +switch(i) +{ +case 1:case 3:case 5:case 7: +case 8:case 10:case 12: month_day[i]=31;break; +case 4:case 6:case 9:case 11: month_day[i]=30;break; +case 2:if( year%400==0 || (year%4==0&&year%100!=0) ) +month_day[i]=29; +else month_day[i]=28; +break; +} +} +for(i=1,n1=0;i<=month-1;i++) +day1=day1+month_day[i]; +day1=day1+dayy; +n1=day1; //n1--¹«Ôª1Äê1ÔÂ1ÈÕ£¬µ½ÊäÈëÈÕÆÚµÄÌìÊý£» + + +t=time(NULL); +local=localtime(&t); +year=local->tm_year+1900; +month=local->tm_mon+1; +dayy=local->tm_mday; +printf("\n½ñÌìµÄÈÕÆÚÊÇ£º%dÄê%dÔÂ%dÈÕ¡£\n",year,month,dayy); + + +day2=day; +for(i=1;i<=12;i++) +{ +switch(i) +{ +case 1:case 3:case 5:case 7: +case 8:case 10:case 12: month_day[i]=31;break; +case 4:case 6:case 9:case 11: month_day[i]=30;break; +case 2:if( year%400==0 || (year%4==0&&year%100!=0) ) +month_day[i]=29; +else month_day[i]=28; +break; +} +} +for(i=1,n2=0;i<=month-1;i++) +day2=day2+month_day[i]; +day2=day2+dayy; +n2=day2; //n2--¹«Ôª1Äê1ÔÂ1ÈÕ£¬µ½µ±Ç°ÈÕÆÚµÄÌìÊý£» + +if(n2>n1) +printf("ÊäÈëÈÕÆÚ¾àÀ뵱ǰϵͳÈÕÆÚ»¹ÓÐ%dÌ죡\n",n2-n1); +else +printf("ÊäÈëÈÕÆÚ¾àÀ뵱ǰϵͳÈÕÆÚ»¹ÓÐ%dÌ죡\n",n1-n2); + + int week; +week=n1%7-1; +switch(week) + { + case 0: + { + printf("ÐÇÆÚÈÕ"); + break; + } + case 1: + { + printf("ÐÇÆÚÒ»"); + break; + } + case 2: + { + printf("ÐÇÆÚ¶þ"); + break; + } + case 3: + { + printf("ÐÇÆÚÈý"); + break; + } + case 4: + { + printf("ÐÇÆÚËÄ"); + break; + } + case 5: + { + printf("ÐÇÆÚÎå"); + break; + } + case 6: + { + printf("ÐÇÆÚÁù"); + break; + } + } +printf("\n"); +main(); + +} + diff --git a/年历显示(修改).exe b/年历显示(修改).exe new file mode 100644 index 0000000..f7cdb8b Binary files /dev/null and b/年历显示(修改).exe differ