複製程式
#include <stdio.h>
#include <stdlib.h>
main()
{
int year, month;
int i, j, nday, leap;
int mdays[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
scanf("%d %d", &month, &year);
if (year < 1900 || year > 2100 || month < 1 || month > 12) {
printf("bad month/year\n");
exit(1);
}
nday = 0;
for (i = 1900; i < year; i++)
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
nday += 366;
else
nday += 365;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
leap = 1;
else
leap = 0;
for (j = 1; j < month; j++)
if (j == 2)
nday += mdays[j] + leap;
else
nday += mdays[j];
printf("%d\n", (1 + nday) % 7);
}
我這是...1900~2100年的@@
是用c寫的^^....
試試看吧!