万年历加强版

/**
 * @copyright 2011 Chunhui Wang
 * 
 * [email protected]
*/

#include<stdio.h>

int main()
{
 printf("\t\t\t万年历\n");
  printf("\t\t\t\t------Made by Chunhui Wang\n\n");
 int i,year, month; 
 int day;//记录每月第一天是周几。 
 int date;//每年星期变化,平年加1,闰年加2。 
 int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};//月份天数 。 
 int Year[10000];//每年第一天周几。 
 Year[1900]=1;
 for(i=1900;i<9999;i++)
 {
  date=1;
  if((i%4==0)&&(i%100!=0)||(i%400==0))
  {
   date=2;
  }
  Year[i+1]=(Year[i]+date)%7;
 }

 while(1)
 {
  printf("请输入年份(如1900):");
  scanf("%d",&year);
  printf("请输入月份(如  01):");
  scanf("%d",&month);


   a[2]=28;
  if(((year%4==0)&&(year%100!=0)||(year%400==0))&&(month>=2))
  {
   a[2]=29;
  }

  day=Year[year];
  for(i=1;i<month;i++)
  {
   day=day+a[i];
  }
  day=day%7;


  printf("\t\t\t\t%d年%d月份\n\n",year,month);
  printf("\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期日\n");
  for(i=0;i<day;i++)
  {
   printf("\t");
  }
  if(day==0)printf("\t\t\t\t\t\t\t");

  for(i=0;i<a[month];i++)
  {
   printf("%d\t",i+1);
   if((i+day)%7==0)
   {
    printf("\n\t");
   }
  } 
  printf("\n\n\n\n");

 }

 return 0;
}

金沙手机APP,  

* @copyright 2011 Chunhui Wang * *
[email protected]*/#includestdio.hint
main(){printf(“\t\t\t万年历\n”); printf(“\t\t\t\t——Made by
Chunhui Wang\n\n”);int i,yea…

相关文章