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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 什么是算法? > 原文: [https://www.programiz.com/dsa/algorithm](https://www.programiz.com/dsa/algorithm) #### 在本教程中,我們將借助示例學習什么算法。 算法是依次解決問題的一組明確定義的指令。 * * * ## 好的算法的質量 1. 輸入和輸出應精確定義。 2. 算法中的每個步驟都應清晰明確。 3. 在解決問題的許多不同方式中,算法應該是最有效的。 4. 算法不應該包含計算機代碼。 相反,應以可以在不同編程語言中使用的方式編寫算法。 * * * ## 算法實例 [將兩個數字相加的算法](#add) [在三個數字中查找最大的算法](#largest) [查找二次方程式](#quadratic)的所有根的算法 [查找階乘](#factorial)的算法 [檢查素數的算法](#prime) [斐波那契數列](#fab)的算法 * * * ## 編程中的算法示例 **編寫一種算法,將用戶輸入的兩個數字相加。** ``` Step 1: Start Step 2: Declare variables num1, num2 and sum. Step 3: Read values num1 and num2\. Step 4: Add num1 and num2 and assign the result to sum. sum←num1+num2 Step 5: Display sum Step 6: Stop ``` **編寫一種算法來查找用戶輸入的三個不同數字中的最大數字。** ``` Step 1: Start Step 2: Declare variables a,b and c. Step 3: Read variables a,b and c. Step 4: If a > b If a > c Display a is the largest number. Else Display c is the largest number. Else If b > c Display b is the largest number. Else Display c is the greatest number. Step 5: Stop ``` **編寫算法來查找二次方程`ax^2 + bx + c = 0`的所有根。** ``` Step 1: Start Step 2: Declare variables a, b, c, D, x1, x2, rp and ip; Step 3: Calculate discriminant D ← b2-4ac Step 4: If D ≥ 0 r1 ← (-b+√D)/2a r2 ← (-b-√D)/2a Display r1 and r2 as roots. Else Calculate real part and imaginary part rp ← b/2a ip ← √(-D)/2a Display rp+j(ip) and rp-j(ip) as roots Step 5: Stop ``` **編寫算法來查找用戶輸入的數字的階乘。** ``` Step 1: Start Step 2: Declare variables n, factorial and i. Step 3: Initialize variables factorial ← 1 i ← 1 Step 4: Read value of n Step 5: Repeat the steps until i = n 5.1: factorial ← factorial*i 5.2: i ← i+1 Step 6: Display factorial Step 7: Stop ``` **編寫算法來檢查用戶輸入的數字是否為質數。** ``` Step 1: Start Step 2: Declare variables n, i, flag. Step 3: Initialize variables flag ← 1 i ← 2 Step 4: Read n from the user. Step 5: Repeat the steps until i=(n/2) 5.1 If remainder of n÷i equals 0 flag ← 0 Go to step 6 5.2 i ← i+1 Step 6: If flag = 0 Display n is not prime else Display n is prime Step 7: Stop ``` **編寫算法來找到直到項`≤ 1000`的斐波那契數列。** ``` Step 1: Start Step 2: Declare variables first_term,second_term and temp. Step 3: Initialize variables first_term ← 0 second_term ← 1 Step 4: Display first_term and second_term Step 5: Repeat the steps until second_term ≤ 1000 5.1: temp ← second_term 5.2: second_term ← second_term + first_term 5.3: first_term ← temp 5.4: Display second_term Step 6: Stop ```
                  <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>

                              哎呀哎呀视频在线观看