302班

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

          結構數組(Time)

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

          #include<stdio.h>

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

          int main(void)
          {
            struct time timeUpdate(struct time now);
            struct time testTimes[5]={{11,59,59},{12,0,0},{1,29,59},{23,59,59},{19,12,27}};
            int i;

            for(i=0;i<5;i++)
            {
              printf("Time is %.2i:%.2i%.2i",testTimes[i].hour,testTimes[i].minutes,testTimes[i].seconds);

           testTimes[i]=timeUpdate(testTimes[i]);

           printf(".....one second later it's %.2i%.2i%.2i\n",
            testTimes[i].hour,testTimes[i].minutes,testTimes[i].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;
          }

          運行結果:

          主站蜘蛛池模板: 朝阳市| 石楼县| 平邑县| 永吉县| 长兴县| 焦作市| 浑源县| 马鞍山市| 濮阳市| 临高县| 怀集县| 苍溪县| 宜州市| 柘城县| 保靖县| 云霄县| 义乌市| 新源县| 迭部县| 荣成市| 馆陶县| 辽阳县| 沙坪坝区| 搜索| 清新县| 石柱| 重庆市| 长汀县| 江孜县| 宝山区| 玛沁县| 农安县| 南江县| 泾源县| 焉耆| 西盟| 阿鲁科尔沁旗| 昌宁县| 社会| 郑州市| 屏南县|