用蔡勒公式计算星期 可以查询具体月份
#include<stdio.h>
#include<string.h>
void year_cd();
void month_cd(int months);
int year,month,day=1,week,i,j,k;
int years[12][6][7]= {0};
int monthname[12]= {31,28,31,30,31,30,31,31,30,31,30,31};
char weekname[]="SUN MON TUE WED THU FRI SAT";
int main() {
char flage;
scanf("%d%c",&year,&flage);
day=year-1+(year-1)/4-(year-1)/100+(year-1)/400+day;
week=day%7;
if((year%4==0&&year%100!=0)||year%400==0) {
monthname[1]=29;
}
if(flage!=32) {
year_cd();
return 0;
}
scanf("%d",&month);
month_cd(month);
printf("%s\n",weekname);
for(i=0; i<6; i++) {
for(j=0; j<7; j++) {
if(years[month-1][i][j]==0) {
printf(" ");
} else {
printf("%-5d",years[month-1][i][j]);
}
}
printf("\n");
}
return 0;
}
void month_cd(int months) {
int days=week;
int nday=1;
for(i=0; i<months-1; i++) {
days+=monthname[i];
}
days=days%7;
for(i=0; i<6; i++) {
for(j=days; j<7; j++) {
days=0;
years[months-1][i][j]=nday++;
if(nday-1==monthname[months-1]) {
return;
}
}
}
}
void year_cd() {
for(k=0; k<12; k++) {
month_cd(k+1);
}
for(i=0; i<12; i+=2) {
printf("%d\t%s\t",i+1,weekname);
printf("%d\t%s\n",i+2,weekname);
for(j=0; j<6; j++) {
printf("\t");
for(k=0; k<14; k++) {
if(k==7)
printf("\t\t");
if(k<7) {
if(years[i][j][k]==0) {
printf(" ");
continue;
}
else {
printf("%-5d",years[i][j][k]);
}
} else {
if(years[i+1][j][k-7]==0) {
printf(" ");
continue;
}
else {
printf("%-5d",years[i+1][j][k-7]);
}
}
}
printf("\n");
}
}
}
|