<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # C 程序:計算整數中的位數 > 原文: [https://www.programiz.com/c-programming/examples/digits-count](https://www.programiz.com/c-programming/examples/digits-count) #### 在此示例中,您將學習計算用戶輸入的整數中的位數。 要理解此示例,您應該了解以下 [C 編程](/c-programming "C tutorial")主題: * [C 編程運算符](/c-programming/c-operators) * [C `while`和`do...while`循環](/c-programming/c-do-while-loops) * * * 該程序從用戶處獲取一個整數并計算位數。 例如:如果用戶輸入 2319,則程序的輸出將為 4。 * * * ## 計算位數的程序 ```c #include <stdio.h> int main() { long long n; int count = 0; printf("Enter an integer: "); scanf("%lld", &n); // iterate until n becomes 0 // remove last digit from n in each iteration // increase count by 1 in each iteration while (n != 0) { n /= 10; // n = n/10 ++count; } printf("Number of digits: %d", count); } ``` **輸出** ```c Enter an integer: 3452 Number of digits: 4 ``` * * * 用戶輸入的整數存儲在變量`n`中。 然后,迭代`while` [循環](https://www.programiz.com/c-programming/c-do-while-loops),直到將測試表達式`n != 0`求值為 0(假)。 * 第一次迭代后,`n`的值為 345,`count`增為 1。 * 在第二次迭代后,`n`的值為 34,`count`遞增為 2。 * 在第三次迭代后,`n`的值為 3,`count`增至 3。 * 在第四次迭代之后,`n`的值將為 0,并且`count`增至 4。 * 然后,將循環的測試表達式求值為`false`,然后循環終止。
                  <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>

                              哎呀哎呀视频在线观看