用C语言写的一个万年历

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>


#include<stdio.h>
#include<math.h>
int input();
void re_year(int year);
void output(int year,int leap,int dis_day,int para);
void main()
{
 int year,leap,dis_day,para;
 while(1)
 {
  year=input();
  re_year(year, &leap,&dis_day,&para);
  output( year, leap, dis_day, para);
 }
}
int input()
{
 int year;
 printf("Please input the year you want to konw:");
 scanf("%d",&year);
 return year;
}
void re_year(int year,int *leap,int *dis_day,int *parameter)
{
 int i,distance;
 *dis_day=0;   
 distance=year-2012; //判断距离2012年的年数
 *leap=(year%4)==0&&(year%100!=0)||year%400==0; //判断是闰年还是平年,闰年返回1,平年返回0
 for(i=1;i<=abs(distance);i++)   //计算输入的年与2012年之间的差值
 {
  if(i%4==0)
  {
   *dis_day+=366;
  }
  else
   *dis_day+=365;
 }
 if(distance<0)       //判断是在2012年之前还是之后
  *parameter=-1;
 else
  *parameter=1;

}
void output(int year,int leap,int dis_day,int para)
{ 
 int i,j,k,m=0;
 int leap_array[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
 {0,31,29,31,30,31,30,31,31,30,31,30,31}};
 int day;   
 int week_day;   //判断是星期几
 day=dis_day%7;
 if(para==1&&year!=2012)     //para为判断是2012年之前还是之后
  week_day=day+1;
 else if(para==-1&&year!=2012)
  week_day=-day+7;
 else if(year==2012)
  week_day=day;
 m=week_day;
 for(i=1;i<13;i++)
 {
  printf("\t%d月\t\n",i);
  printf("%s %s %s %s %s %s %s\n","Sun","Mon","Tus","Wes","Ths","Fri","Sat");
  if(m==0)
   m++;
  else if(m!=7)
  {
   for(k=1;k<=m;k++)
    printf("    ");
   m++;
  }
  for(j=1;j<=leap_array[leap][i];j++)
  {
   if(m%7==0)
   {
    printf("%3d\n",j);
   }
   else
    printf("%3d ",j);
   m++;

  }
  m=(m-1)%7;
  printf("\n");
 }
 
}