输入年月日时分秒,输出下一秒的时间。

#include "stdio.h"
void main()
{
int yea,mon,day,hou,min,sec;
while(1)
{
printf("请输入年月日时分秒!\n");
scanf("%d%d%d%d%d%d",&yea,&mon,&day,&hou,&min,&sec);
printf("你输入的是时间是:\n%d年%d月%d日%d小时%d分%d秒\n",yea,mon,day,hou,min,sec);
if(mon>0&&mon<13&&day<32&&day>0&&hou<24&&hou>-1&&min>-1&&min<60&&sec>-1&&sec<60)
{
sec = sec + 1; //秒数____进位判断
if (sec == 60)
{
sec = 0;
min = min + 1;
}
if (min == 60)
{
min = 0;
hou = hou + 1;
}
if (hou == 24)
{
hou = 0;
day = day + 1;
}
/*____根据秒数判断:算到___天,day向month进位时__需要考虑分为30天__和31天__的月份,最重要的是考虑__闰年的2月__!____*/


/*_____________________________________________________*/


if ((yea%400 == 0)||((yea%4 == 0) && (yea%100 != 0)) ) //闰年
{
if(mon == 2) //2 月
{
if(day == 30)//______________________________________________________________期间写错一次,因为把 ==  写成了  =  !!!!!
{
day = 1;
mon = mon + 1;
}
}
if(mon ==1||mon ==3||mon ==5||mon ==7||mon ==8||mon ==10||mon ==12) //1.3.5.7.8.10.12
{
if(day == 32)
{
day = 1;
mon  = mon + 1;
}
}
if(mon ==4||mon ==6||mon ==9||mon ==11) //4.6.9.11
{
if(day == 31)
{
day = 1;
mon = mon +1;
}
}
if(mon == 13)
{
mon = 1;
yea = yea + 1;
}
}
/*_______________________________________________*/
else //非闰年
{
if(mon ==1||mon ==3||mon ==5||mon ==7||mon ==8||mon ==10||mon ==12) //1.3.5.7.8.10.12
{
if(day == 32)
{
day = 1;
mon  = mon + 1;
}
}
if(mon == 2||mon ==4||mon ==6||mon ==9||mon ==11) //2.4.6.9.11
{
if(day == 31)
{
day = 1;
mon = mon +1;
}
}
if(mon == 13)
{
mon = 1;
yea = yea + 1;
}
}
printf("下一秒是:\n");
printf("%d年%d月%d日%d时%d分%d秒\n\n",yea,mon,day,hou,min,sec);
fflush(stdin);
}
else printf("请输入正确的年月日!\n\n");
    fflush(stdin);
}

}

//DD  为啥我的没有像编译器里的代码那种显示风格

你可能感兴趣的:(时间,下一秒,输出下一秒,输入时间,C)