第1个回答 2011-06-17
#include<stdio.h>
#include<stdlib.h> 。
int IsLeapYear(int year)
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;
}
int month_day(int year,int month)
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(IsLeapYear(year)&&month==2)
return 29;
else
return(mon_day[month-1]);
}
int DaySearch(int year,int month,int day)
{
int c=0;
float s;
int m;
for(m=1;m<month;m++)
c=c+month_day(year,m);
c=c+day;
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
return ((int)s%7);
}
int PrintAllYear(int year)
{
int temp;
int i,j;
printf("\n\n%d year\n",year);
for(i=1;i<=12;i++)
{
temp=DaySearch(year,i,1);
if(i==1)
{
if(temp==0) printf("\n first day is %d\n",7);
else printf("\n first day is %d\n",temp);
}
printf("\n\n%d month\n",i);
printf(" S M T W T F S \n");
for(j=1;j<=month_day(year,i)+temp;j++)
{
if(j-temp<=0)
printf(" ");
else
printf("%3d",j-temp);
if(j%7==0)
printf("\n");
}
}
return 0;
}
void main()
{
int year;
printf("\nPlease input a year(XXXX)");
scanf("%d",&year);
PrintAllYear(year);
}本回答被提问者采纳