输入年月日时分秒,计算下一秒的年月日时分秒
1.名称:时光飞逝
2.描述:输入年月日时分秒,计算下一秒的年月日时分秒
3.分析:
1.定义六个全局变量
2.输入时间
3.计算下一秒
3.1 second加一秒
3.2 计算每月对应的天数
3.3 计算闰年
4.打印
4.模块
1.输入模块 void input()
2.计算下一秒 void nextMinute()
3.计算每月对应的天数 int dayMonth()
4.判断是否是闰年 int isLeapYear()
5.打印 void print()
1 #include <stdio.h> 2 3 int year,month,day,hour,minute,second; 4 5 void input(){ 6 scanf("%d%d%d%d%d%d", &year, &month, &day, &hour, &minute, &second); 7 } 8 void nextSecond(){ 9 if(++second==60){ 10 second = 0; 11 minute++; 12 } 13 if(minute==60){ 14 minute = 0; 15 hour++; 16 } 17 if(hour==24){ 18 hour = 0; 19 day++; 20 } 21 if(day==dayMonth()){ 22 day = 1; 23 month++; 24 } 25 if(month==13){ 26 month = 1; 27 year++; 28 } 29 } 30 int dayMonth(){ 31 if(month==2){ 32 if(isLeapYear()) 33 return 30; 34 else 35 return 29; 36 } 37 else if(month==4||month==6||month==9||month==11) 38 return 31; 39 else 40 return 32; 41 } 42 int isLeapYear(){ 43 if(year%400==0 || year%4==0&&year%100!=0) 44 return 1; 45 else 46 return 0; 47 } 48 void print(){ 49 printf("%d-%d-%d %d:%d:%d\n", year, month, day, hour, minute, second); 50 } 51 52 int main() 53 { 54 puts("请输入年月日时分秒:"); 55 input(); 56 nextSecond(); 57 puts("下一秒是:"); 58 print(); 59 }