<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://beginnersbook.com/2017/09/c-program-to-convert-binary-to-octal-number-system/](https://beginnersbook.com/2017/09/c-program-to-convert-binary-to-octal-number-system/) 該 C 程序將二進制數轉換為等效的八進制數。 ## 示例:將二進制轉換為八進制的程序 在該程序中,要求用戶輸入二進制數,然后程序通過調用用戶定義的函數將該二進制數轉換為八進制數。要理解這個程序,您應該熟悉以下 [C 編程](https://beginnersbook.com/2014/01/c-tutorial-for-beginners-with-examples/)概念: 1. [C - `while`循環](https://beginnersbook.com/2014/01/c-while-loop/) 2. [C - 函數](https://beginnersbook.com/2014/01/c-functions-examples/) ```c #include <stdio.h> #include <math.h> //This function converts binary number to octal number int binaryToOctal(long binarynum) { int octalnum = 0, decimalnum = 0, i = 0; /* This while loop converts binary number "binarynum" to the * decimal number "decimalnum" */ while(binarynum != 0) { decimalnum = decimalnum + (binarynum%10) * pow(2,i); i++; binarynum = binarynum / 10; } //i is re-initialized i = 1; /* This loop converts the decimal number "decimalnum" to the octal * number "octalnum" */ while (decimalnum != 0) { octalnum = octalnum + (decimalnum % 8) * i; decimalnum = decimalnum / 8; i = i * 10; } //Returning the octal number that we got from binary number return octalnum; } int main() { long binarynum; printf("Enter a binary number: "); scanf("%ld", &binarynum); // calling the function here printf("Equivalent octal value: %d", binaryToOctal(binarynum)); return 0; } ``` **輸出:** ```c Enter a binary number: 111001 Equivalent octal value: 71 ``` 在這個程序中,我們首先將輸入的二進制數轉換為十進制數,然后我們將該十進制數轉換為八進制數。 看看這些相關的 C 程序: 1. [C 程序:將二進制轉換為十進制](https://beginnersbook.com/2015/02/c-program-to-convert-binary-number-to-decimal-number/) 2. [C 程序:將十進制數轉換為二進制數](https://beginnersbook.com/2017/09/c-program-to-convert-decimal-number-to-binary-number/) 3. [C 程序:將八進制數轉換為二進制數](https://beginnersbook.com/2017/09/c-program-to-convert-octal-number-to-binary-number/) 4. [C 程序:將小寫字符串轉換為大寫](https://beginnersbook.com/2015/02/c-program-to-convert-lowercase-string-to-uppercase-string/) 5. [C 程序:將大寫字符串轉換為小寫](https://beginnersbook.com/2015/02/c-program-to-convert-uppercase-string-to-lowercase-string/)
                  <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>

                              哎呀哎呀视频在线观看