#include
#include
#include
#include
void main()
{ do{
time_t *tp;
struct tm *tmptr;
int year,mon,matrix[7][6],m,n,max,i;
tp=(time_t *)malloc(sizeof(time_t));
tmptr=(struct tm *)malloc(sizeof(struct tm));
for(m=0;m2039))
{
printf ("Error!The year must between 1970 and 2039!\nInput the year:");
scanf("%d",&year);
}
printf("\nPlease input the month:");
scanf("%d",&mon);
while ((mon12))
{
printf ("\nError!The month must between 1 and 12!\n");
scanf("%d",&mon);
}
printf("%d-%d\n",year,mon);
tmptr->tm_sec=0;
tmptr->tm_min=0;
tmptr->tm_hour=0;
tmptr->tm_mday=1;
tmptr->tm_mon=mon-1;
tmptr->tm_year=year-1900;
*tp=mktime(tmptr);
tmptr=localtime(tp);
switch (mon){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
max=31;
break;
case 4: case 6: case 9: case 11:
max=30;
break;
case 2:
if((year%4==0&&year%100!=0)||(year%400==0))
max=29;
else
max=28;
break;
}
for(n=tmptr->tm_wday,i=1;n<7;n++)
matrix[0][n]=i++;
for(m=1;m<6;m++)
for(n=0;n<7&&i<=max;n++)
matrix[m][n]=i++;
printf(" SUN MON TUS WES THU FRI SAT \n");
for(m=0;m<6;m++){
for(n=0;n<7;n++)
if(matrix[m][n]!=0)
printf("%4d",matrix[m][n]);
else printf("
");
printf("\n");
}
printf("Do you want to use again?(y\\n)");
getchar();
}
while(getchar()=='y');
}
帮忙找下错误,并修改!
|