/*
根据输入的日期,计算第二天的日期
基本内容都很简单,就不需要多说了。
呵呵,很早的一个练习的例子,
放这里予以纪念 ^_^
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int y,m,d;
int f, fwrong=0;
printf("y,m,d=");
scanf("%d%d%d",&y,&m,&d); /*输入格式: 1996 2 28, 空格分割数据*/
f= ( (y%4==0) && (y%100!=0) ) || (y%400==0);
switch(m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(d<31)d++;
else if(d == 31)
{
if(m != 12){m++; d=1;}
else {y++; m=1; d=1;}
}
else {fwrong=1; printf("The date is wrong!!/n");}
break;
case 4:
case 6:
case 9:
case 11:
if(d<30)d++;
else if(d == 30){m++; d=1;}
else {fwrong=1; printf("The date is wrong!!/n");}
break;
case 2:
if(f)
{
if(d<28)d++;
else if(d == 28){m++; d=1;}
else {fwrong=1; printf("The date is wrong!!/n");}
break;
}
else
{
if(d<29)d++;
else if(d == 29){m++; d=1;}
else {fwrong=1; printf("The date is wrong!!/n");}
break;
}
}
if(!fwrong)
printf("The date of next day is %d,%d,%d", y, m, d);
system("PAUSE");
return 0;
}
根据输入的日期,计算第二天的日期
基本内容都很简单,就不需要多说了。
呵呵,很早的一个练习的例子,
放这里予以纪念 ^_^
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int y,m,d;
int f, fwrong=0;
printf("y,m,d=");
scanf("%d%d%d",&y,&m,&d); /*输入格式: 1996 2 28, 空格分割数据*/
f= ( (y%4==0) && (y%100!=0) ) || (y%400==0);
switch(m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(d<31)d++;
else if(d == 31)
{
if(m != 12){m++; d=1;}
else {y++; m=1; d=1;}
}
else {fwrong=1; printf("The date is wrong!!/n");}
break;
case 4:
case 6:
case 9:
case 11:
if(d<30)d++;
else if(d == 30){m++; d=1;}
else {fwrong=1; printf("The date is wrong!!/n");}
break;
case 2:
if(f)
{
if(d<28)d++;
else if(d == 28){m++; d=1;}
else {fwrong=1; printf("The date is wrong!!/n");}
break;
}
else
{
if(d<29)d++;
else if(d == 29){m++; d=1;}
else {fwrong=1; printf("The date is wrong!!/n");}
break;
}
}
if(!fwrong)
printf("The date of next day is %d,%d,%d", y, m, d);
system("PAUSE");
return 0;
}