1. 万年历(1990之后)
#include<stdio.h>
int main()
{
int year,month;
int i=1900;
int sum=0;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("please input year and month:");
scanf("%d%d",&year,&month);
if(year<1990 || (month<1 || month>12))
{
printf("input error");
}
else
{
while(i<year)
{
if((i%4==0 && i%100!=0) || i%400==0)
{
sum+=366;
}
else
{
sum+=365;
}
i++;
}
if((year%4==0 && year%100!=0) || year%400==0)
{
a[2]=29;
}
else
{
a[2]=28;
}
printf("%d\n",a[2]);
int j=1;
while(j<month)
{
sum=sum+a[j];
j++;
}
}
int week=sum%7;
//printf("week=%d\n",week);
week=(week+1)%7;
printf("\t\t\t%d/%d\n",year,month);
printf("Sun\tMon\tTues\tWed\tThur\tFri\tSat\n");
int colum=0;
i=1;
int b=a[month];
while (i<=week)
{
printf("\t");
i++;
colum++;
}
i=1;
while(i<=b)
{
printf("%2d\t",i);
colum++;
if(colum%7==0)
{
printf("\n");
}
i++;
}
printf("\n");
return 0;
}
网友评论