#include <stdio.h>
#include <windows.h>
///////////////////////////////////////´òÓ¡ÈÕÀú////////////////////////////////////////////////////////////////////////////////
int Month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
int CalcWeek(int y, int m, int d)//»ùÄ·À¶ûɼÆË㹫ʽ
{
int w;
if (m == 1 || m == 2)
{
m += 12;
y--;
}
w = (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) % 7 + 1;
return w;
}
void PrintCalendar(int y, int m, int d)
{
int w,i;
int day = 1;//´Ó1ºÅ¿ªÊ¼´òÓ¡
w = CalcWeek(y,m,1);//¸ÃÔ£¬1ºÅÊÇÐÇÆÚ¼¸¡£
printf("\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN);
printf("Ò» ¶þ Èý ËÄ Îå Áù ÈÕ\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
while (1)
{
for (i=1; i<=7; i++)//Ò»ÖÜÆßÌ죬ѻ·´òÓ¡Æ߸öÈÕÆÚ
{
if (i < w)
{
printf(" ");
}
else
{
if (day == d)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED);
printf("%-4d", day++);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
}
else
{
printf("%-4d", day++);
}
}
if (day > Month[m-1])//
{
printf("\n");
return;//
}
}
w = 1;//ÿ¸öÔµĵÚÒ»Öܹýºó£¬Ã¿Ò»Öܶ¼ÊÇ´ÓÖÜÒ»¿ªÊ¼´òÓ¡
printf("\n");
}
}
int main()
{
int y,m,d;
printf("ÇëÊäÈëÄêÔÂÈÕ:");
scanf("%d%d%d", &y, &m, &d);
PrintCalendar(y, m, d);//´òÓ¡ÈÕÀú
printf("\n\n");
return 0;
}