<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # C 程序:計算兩個時間段之間的差異 > 原文: [https://www.programiz.com/c-programming/examples/time-structure](https://www.programiz.com/c-programming/examples/time-structure) #### 在此示例中,您將學習使用用戶定義的函數計算兩個時間段之間的差。 要理解此示例,您應該了解以下 [C 編程](/c-programming "C tutorial")主題: * [C 用戶定義的函數](/c-programming/c-user-defined-functions) * [C 結構](/c-programming/c-structures) * [C 結構和函數](/c-programming/c-structure-function) * [C 結構和指針](/c-programming/c-structures-pointers) * * * ## 計算兩個時間段之間的差異 ```c #include <stdio.h> struct TIME { int seconds; int minutes; int hours; }; void differenceBetweenTimePeriod(struct TIME t1, struct TIME t2, struct TIME *diff); int main() { struct TIME startTime, stopTime, diff; printf("Enter the start time. \n"); printf("Enter hours, minutes and seconds: "); scanf("%d %d %d", &startTime.hours, &startTime.minutes, &startTime.seconds); printf("Enter the stop time. \n"); printf("Enter hours, minutes and seconds: "); scanf("%d %d %d", &stopTime.hours, &stopTime.minutes, &stopTime.seconds); // Difference between start and stop time differenceBetweenTimePeriod(startTime, stopTime, &diff); printf("\nTime Difference: %d:%d:%d - ", startTime.hours, startTime.minutes, startTime.seconds); printf("%d:%d:%d ", stopTime.hours, stopTime.minutes, stopTime.seconds); printf("= %d:%d:%d\n", diff.hours, diff.minutes, diff.seconds); return 0; } // Computes difference between time periods void differenceBetweenTimePeriod(struct TIME start, struct TIME stop, struct TIME *diff) { while (stop.seconds > start.seconds) { --start.minutes; start.seconds += 60; } diff->seconds = start.seconds - stop.seconds; while (stop.minutes > start.minutes) { --start.hours; start.minutes += 60; } diff->minutes = start.minutes - stop.minutes; diff->hours = start.hours - stop.hours; } ``` **輸出** ```c Enter the start time. Enter hours, minutes and seconds: 12 34 55 Enter the stop time. Enter hours, minutes and seconds: 8 12 15 Time Difference: 12:34:55 - 8:12:15 = 4:22:40 ``` * * * 在該程序中,要求用戶輸入兩個時間段,這兩個時間段分別存儲在結構變量`startTime`和`stopTime`中。 然后,函數`differenceBetweenTimePeriod()`計算時間段之間的差。 結果從`main()`函數顯示而不返回(使用**按引用調用**技術)。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看