diff --git a/年历2.c b/年历2.c new file mode 100644 index 0000000..28222a2 --- /dev/null +++ b/年历2.c @@ -0,0 +1,271 @@ +#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; +} +getchar();getchar();getchar();getchar(); +return 0; +} + + +void menu() +{ +printf("-----------------------------------------------------------------\n"); +printf(" »¶Ó­À´µ½ÈÕÀú²éѯϵͳ \n"); +printf(" 1:²éѯijÄêÈÕÀú \n"); +printf(" 2:²éѯijÄêijÔµÄÈÕÀú \n"); +printf(" 3:²éѯijÄêÔÂÈÕµÄÈÕÀúÐÅÏ¢ \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 "); +} + +} + + + +} + + +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"); +} +} + + + + +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&&dayy==1) || (month==5&&dayy==1) || (month==10&&dayy==1)) +printf("ÊäÈëÈÕÆÚÊÇ·¨¶¨¼ÙÈÕ£¡\n"); +else printf("ÊäÈëÈÕÆÚ²»ÊÇ·¨¶¨¼ÙÈÕ£¡\n"); + + +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); +if((month==1&&dayy==1) || (month==5&&dayy==1) || (month==10&&dayy==1)) +printf("µ±Ç°ÈÕÆÚÊÇ·¨¶¨¼ÙÈÕ£¡\n"); +else printf("µ±Ç°ÈÕÆÚ²»ÊÇ·¨¶¨¼ÙÈÕ£¡\n"); +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; + } + } + + +} + diff --git a/年历2.exe b/年历2.exe new file mode 100644 index 0000000..a087e30 Binary files /dev/null and b/年历2.exe differ