#include<stdio.h>#include<string.h>#include<stdlib.h>struct time{ int hour; int minute; int second;};struct time TimeUpdate(struct time now);int main(int argc,char const argv[]){ int i; struct time testtimes[5]={{23,59,59},{12,52,36},{06,12,58},{00,00,00},{25,01,26}}; for(i=0;i<5;i++) { printf("Time is %02d:%02d:%02d\n",testtimes[i].hour ,testtimes[i].minute ,testtimes[i].second ); testtimes[i]=TimeUpdate(testtimes[i]); printf("...one second after the now time is %02d:%02d:%02d\n",testtimes[i].hour ,testtimes[i].minute ,testtimes[i].second); getchar(); } return 0;}struct time TimeUpdate(struct time now){ if(now.hour>=0&&now.hour<24) { if(now.second>=60) { now.minute=now.minute +now.second /60; now.second=now.second-60*(now.second/60); if(now.minute>=60) { now.hour=now.hour+now.minute/60; now.minute=now.minute-60*(now.minute/60); } } printf("您输入的标准时间格式是 %02d:%02d:%02d\n",now.hour,now.minute ,now.second ); ++now.second; if(now.second ==60) { now.second=0; ++now.minute; if(now.minute==60) { now.minute=0; ++now.hour; if(now.hour==24) { now.hour =0; } } } } else { printf("时间输入有误!\n"); }}
- 2 回答
- 0 关注
- 1476 浏览
添加回答
举报
0/150
提交
取消