diff --git a/年历.c b/年历.c new file mode 100644 index 0000000..f27ee4d --- /dev/null +++ b/年历.c @@ -0,0 +1,97 @@ +#define MAIN_H +#include "stdio.h" +#include "math.h" +#include "stdlib.h" + +//»ñȡijһ¸öÔµÄ×î´óÌìÊý +int monthday(int,int ); + +//ÅжÏÈòÄê ,ÊÇ·µ»Ø1£¬²»ÊÇ·µ»Ø0 +int isleapyear(int ); + +#include + +int main() +{ + int year,month,days,weekday; + int i,d; + while(1) + { + printf("please input the year:\n"); + scanf("%d",&year); + days = year-1+(year-1)/400+(year-1)/4-(year-1)/100;//¼ÆËãijÄêµÚÒ»ÌìÊÇÐÇÆÚ¼¸ + + for(month=1;month<=12;month++) + { + printf("\n--------%d/%d--------\n",year,month); + printf("sun\tmon\ttues\twed\tthur\tfir\tsat\t\n");//±íÍ· + i = 1; d = 1; + weekday = (days + 1)%7; //ÇóÐÇÆÚ¼¸ + while(i<=weekday) //Êä³öÇ°ÃæµÄ¿Õ¸ñ + { + printf("\t"); + i++; + } + + while(d<=monthday(month,year)) //Êä³öÈÕÆÚ + { + weekday = (days + 1)%7; + if(weekday==6) //×îºóÒ»¸öÊÇÐÇÆÚÁù£¬Êä³öÖ®ºóÒª»»ÐÐ + printf("%d\n",d); + else //²»ÊÇÐÇÆÚÁùµÄÊä³öºó²»»»ÐÐ + printf("%d\t",d); + if(d==monthday(month,year)) + printf("\n"); + d++; + days++; + } + } + } + +} + +#include "math.h" + +int monthday(int month,int year) +{ + switch(month) + { + case 1: + case 3: + case 5: + case 7: + case 8: + case 10: + case 12: + return 31;break; + + case 4: + case 6: + case 9: + case 11: + return 30;break; + + case 2: + if(isleapyear(year)) + { + return 29;//ÈòÄê29Ìì + break; + } + else + { + return 28; + break; + } + + } + +} + + +int isleapyear(int year) +{ + if((year%4==0)&&(year%100!=0)||(year%400==0)) + return 1; + else + return 0; +} diff --git a/年历.exe b/年历.exe new file mode 100644 index 0000000..6f88efb Binary files /dev/null and b/年历.exe differ