You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
3.1 KiB

6 years ago
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<>
// ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include<math.h>
int month_day(int year,int month)
{
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((year%4==0)&&(year%100!=0)||(year%400==0))
{
return 29;
break;
}
else
{
return 28;
break;
}
}
}
// <20><><EFBFBD><EFBFBD>
void year_calendar(int year)
{
int month,days,weekday,sum_day;
int i,j;
year;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>");
scanf("%d",&year);
for(i=1;i<year;i++)
{
if((year%4==0)&&(year%100!=0)||(year%400==0))
sum_day+=366;
else
sum_day+=365;
}
for(month=1;month<=12;month++)
{
printf("\n--------%d/%d--------\n",year,month);
printf("SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\t\n");
i=1;
j=1;
weekday=sum_day%7;
while(i<=weekday) //<2F><>ʼλ<CABC><CEBB>ǰ<EFBFBD><C7B0><EFBFBD>ǿո<C7BF>
{
printf("\t");
i++;
}
while(j<=month_day(year,month))
{
weekday=sum_day%7;
if (weekday==6)
printf("%d\n",j);
else
printf("%d\t",j);
if(j==month_day(year,month))
printf("\n");
j++;
sum_day++;
}
}
}
// <20><><EFBFBD><EFBFBD>
void month_calendar(int year,int month)
{
int sum_day=0,weekday,i,j,k;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F>£<EFBFBD>");
scanf("%d/%d",&year,&month);
for(i=1;i<year;i++)
{
if((year%4==0)&&(year%100!=0)||(year%400==0))
sum_day+=366;
else
sum_day+=365;
}
for(k=1;k<month;k++)
{
sum_day+=month_day(year,month);
}
printf("\n--------%d/%d--------\n",year,month);
printf("SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\t\n");
i=1;
j=1;
weekday=sum_day%7;
while(i<=weekday) //<2F><>ʼλ<CABC><CEBB>ǰ<EFBFBD><C7B0><EFBFBD>ǿո<C7BF>
{
printf("\t");
i++;
}
while(j<=month_day(year,month))
{
weekday=sum_day%7;
if (weekday==6)
printf("%d\n",j);
else
printf("%d\t",j);
if(j==month_day(year,month))
printf("\n");
j++;
sum_day++;
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_day;
int tm_month;
int tm_year;
int tm_weekday;
int tm_yearday;
}
int main(void)
{
printf("\n-------------------ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-------------------\n\n");
printf(" 1.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ\n");
printf(" 2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ\n");
printf(" 3.<2E><><EFBFBD>ڲ<EFBFBD>ѯ\n");
printf(" 4.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf(" 5.<2E>˳<EFBFBD>\n");
printf("\n-------------------ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-------------------\n") ;
int n,year,month,day;
printf("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d",&n);
switch(n)
{
case 1:
{
year_calendar(year);
break;
}
case 2:
{
month_calendar(year,month);
break;
}
}
}