302班

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

          結構數組(Time)

          Posted on 2007-07-02 20:09 停留的風 閱讀(263) 評論(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;
          }

          運行結果:

          主站蜘蛛池模板: 阳西县| 开原市| 子洲县| 青海省| 铜陵市| 泰来县| 云阳县| 连州市| 平武县| 深圳市| 开封市| 玛曲县| 潜江市| 乌兰浩特市| 孝感市| 北辰区| 水城县| 克山县| 昭平县| 河北区| 宁乡县| 察隅县| 青龙| 光泽县| 灵山县| 石阡县| 富锦市| 巴彦淖尔市| 益阳市| 清新县| 祥云县| 普安县| 合山市| 红原县| 新泰市| 黑河市| 泾阳县| 桃源县| 建平县| 邛崃市| 五大连池市|