#include"stdio.h"
void weekday();
int _2000yera(int x)
{
int sum=0;
int i;
if(x>=2000){
for(i=2000;i<x;i++)
{
sum+=(i%4==0&&i%100==0||i%400==0)?366:365;
}
return (sum+6)%7;
}
else{
for(i=x;i<2000;i++)
{
sum+=(i%4==0&&i%100==0||i%400==0)?366:365;
}
return (-sum%7+6)%7;
}
}
void weekday()
{
int i;
for(i=1;i<=7;i++)
printf("%d\t",i);
printf("\n");
}
int sp(int x)
{
int i;
for(i=1;i<=_2000yera(x);i++)
printf("\t");
return i;
}
int month(int ch,int x)
{
switch(ch)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:return 31;
case 4:
case 6:
case 9:
case 11:return 30;
case 2:
return leap(x)?29:28;
}
}
int leap(int x)
{
return x%4==0&&x%100!=0||x%400==0?0:1;
}
int printyear(int x)
{
int mon,i=1,j,day;
printf("*********1*********");
weekday();
printf("\n");
i=sp(x);
for(day=1,mon=1;mon<=12;mon++)
{
for(j=1;j<=month(mon,x);j++,i++,day++)
{
printf("%d\t",j);
if(i%7==0){printf("\n");day=1;}
}
if(mon<12){
printf("\n");
printf("*********%d*********\n",mon+1);
weekday();
printf("\n");
i=1;
i+=day-2;
for(;day-2>0;day--)
printf(" \t");}
}
}
main()
{
int x;
printf("year:");
scanf("%d",&x);
printyear(x);
getch();
}
在C-Free 3.5下 就是死循环啊
在TC下可以啊