给出年、月、日,加一天
给出年、月、日,加一天,请计算出是哪年、哪月、哪日。
程序代码:#include<stdio.h>
#include<time.h>
int
main(void)
{
struct tm t;
int temp,flag=0;
int day_tab[2][12]={
{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,30,30,31,30,31}
};
printf("input year: ");
scanf("%d",&temp);
if(temp<1900)
{
printf("Yeild !");
exit(0);
}
if(temp%4==0 && temp%100!=0 || temp%400==0)
flag=1;
t.tm_year=temp-1900;
/*printf("%d\n",t.tm_year); */
fflush(NULL);
printf("input Mon: ");
scanf("%d",&temp);
if(temp>12 || temp<1)
{
printf("Error!");
exit(0);
}
t.tm_mon=temp-1;
/* printf("%d\n",t.tm_mon); */
fflush(NULL);
printf("input day: ");
scanf("%d",&temp);
temp+=1;
/*printf("%d\n",day_tab[flag][t.tm_mon]); */
if(temp>day_tab[flag][t.tm_mon]+1 || temp<0)
{
printf("Error");
getch();
exit(0);
}
else if(temp==day_tab[flag][t.tm_mon]+1)
{
temp=1;
t.tm_mon++;
}
t.tm_mday=temp;
fflush(NULL);
printf("input wday: ");
scanf("%d",&temp);
temp++;
temp=temp%7;
t.tm_wday=temp;
printf("The next day is: %s",asctime(&t));
getch();
return 0;
}输入年,月,日,星期