万年历

#include <stdio.h>
int year (int y)
{
	if ((y%4==0) && (y%100!=0) || y%400==0)
		return 366;
	else 
		return 365;
}
int main ()
{
	int y,i,j,begin,sum=0;
	int week;
	int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
	printf ("==========万年历===========\n\n\n");
	printf ("请输入年份:");
	scanf ("%d",&y);
	
	for (i=1;i<y;i++)
		sum+=year(i);
	week=(sum+1)%7;
	if (year(y)==366)
		days[1]=29;
	printf ("\n%d年的日历为:\n\n\n",y);
	for (i=0;i<12;i++)
	{
      printf ("        %d月     \n\n",i+1);
	  printf (" 日 一 二 三 四 五 六\n");
	  
	  for (j=0;j<week;j++)
			printf ("   ");
		for (begin=1;begin<=days[i];begin++)
		{
				printf("%3d",begin);
			week=(week+1)%7;
			if (week%7==0)
				printf ("\n");
		}
	  
			printf ("\n========================\n\n");
	}
         return 0;
}

你可能感兴趣的:(万年历)