302班

          java突擊隊
          posts - 151, comments - 74, trackbacks - 0, articles - 14
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          日歷

          <2007年7月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          搜索

          •  

          積分與排名

          • 積分 - 154334
          • 排名 - 394

          最新評論

          time的更新、設置

          Posted on 2007-07-02 19:50 停留的風 閱讀(254) 評論(0)  編輯  收藏 所屬分類: C語言學習歷程

          #include<stdio.h>

          struct time
          {
            int hour;
            int minutes;
            int seconds;
          };

          int main(void)
          {
            struct time timeUpdate(struct time now);
            struct time currentTime,nextTime;

            printf("Enter the time (hh:mm:ss).\n");
            scanf("%i:%i:%i",&currentTime.hour,&currentTime.minutes,&currentTime.seconds);

            nextTime=timeUpdate(currentTime);
            printf("Updated time is %.2i:%.2i:%.2i\n",nextTime.hour,nextTime.minutes,nextTime.seconds);

            return 0;
          }

          struct time timeUpdate(struct time now)
          {
            ++now.seconds;
            if(now.seconds==60)
            {
              now.seconds=0;
           ++now.minutes;
           if(now.minutes==60)
           {
             now.minutes=0;
             ++now.hour;
             if(now.hour=24)
              now.hour=0;
           }
            }
            return now;
          }

          測試結果:

          主站蜘蛛池模板: 天门市| 岑巩县| 德庆县| 四子王旗| 吉安市| 灌云县| 新邵县| 逊克县| 晋江市| 金阳县| 桐梓县| 新龙县| 思茅市| 盐池县| 固阳县| 务川| 灵武市| 八宿县| 蒙自县| 荆州市| 岳阳县| 兰西县| 治多县| 濮阳市| 丹阳市| 油尖旺区| 石渠县| 光泽县| 阿瓦提县| 天柱县| 霍林郭勒市| 五原县| 阳朔县| 华亭县| 林州市| 南川市| 大兴区| 苏尼特右旗| 郸城县| 桂林市| 开阳县|