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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # C++ 程序:查找階乘 > 原文: [https://www.programiz.com/cpp-programming/examples/factorial](https://www.programiz.com/cpp-programming/examples/factorial) #### 正整數 n 的階乘等于`1 * 2 * 3 * ... n`。 在此示例中,您將學習使用`for`循環來計算數字的階乘。 要理解此示例,您應該了解以下 [C++ 編程](/cpp-programming "C++ tutorial")主題: * [C++ `for`循環](/cpp-programming/for-loop) * * * 對于任何正數`n`,階乘由下式給出: ```cpp factorial = 1*2*3...*n ``` 找不到負數的階乘,0 的階乘為 1。 在下面的該程序中,要求用戶輸入一個正整數。 然后,該數字的階乘被計算并顯??示在屏幕中。 * * * ## 示例:查找給定數字的階乘 ```cpp #include <iostream> using namespace std; int main() { unsigned int n; unsigned long long factorial = 1; cout << "Enter a positive integer: "; cin >> n; for(int i = 1; i <=n; ++i) { factorial *= i; } cout << "Factorial of " << n << " = " << factorial; return 0; } ``` **輸出** ```cpp Enter a positive integer: 12 Factorial of 12 = 479001600 ``` 在此,變量`factorial`的類型為`unsigned long long`。 這是因為數字的階乘始終為正,這就是為什么要在其中添加`unsigned`限定詞的原因。 由于階乘數可能很大,因此將其定義為`long long`。
                  <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>

                              哎呀哎呀视频在线观看