<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之旅 廣告
                # 未排序數組的均值和中位數的程序 > 原文: [https://www.geeksforgeeks.org/program-for-mean-and-median-of-an-unsorted-array/](https://www.geeksforgeeks.org/program-for-mean-and-median-of-an-unsorted-array/) 給定 **n** 大小的未排序數組,找到其均值和中位數。 > **數組的平均值** =(所有元素的總和)/(元素數量) **大小為`n`的排序數組的中位數**當`n`為奇數時定義為中間元素,而當`n`為偶數時定義為中間兩個元素的平均值。 由于此處未對數組進行排序,因此我們首先對數組進行排序,然后應用上述公式。 **示例**: ``` Input : a[] = {1, 3, 4, 2, 6, 5, 8, 7} Output : Mean = 4.5 Median = 4.5 Sum of the elements is 1 + 3 + 4 + 2 + 6 + 5 + 8 + 7 = 36 Mean = 36/8 = 4.5 Since number of elements are even, median is average of 4th and 5th largest elements. which means (4 + 5)/2 = 4.5 Input : a[] = {4, 4, 4, 4, 4} Output : Mean = 4 Median = 4 ``` 下面是代碼實現: ## C++ ```cpp // CPP program to find mean and median of? // an array #include <bits/stdc++.h> using namespace std; // Function for calculating mean double findMean(int a[], int n) { ????int sum = 0; ????for (int i = 0; i < n; i++)? ????????sum += a[i]; ????return (double)sum/(double)n; } // Function for calculating median double findMedian(int a[], int n) { ????// First we sort the array ????sort(a, a+n); ????// check for even case ????if (n % 2 != 0) ???????return (double)a[n/2]; ????return (double)(a[(n-1)/2] + a[n/2])/2.0; } // Driver program int main() { ????int a[] = { 1, 3, 4, 2, 7, 5, 8, 6 }; ????int n = sizeof(a)/sizeof(a[0]); ????cout << "Mean = " << findMean(a, n) << endl;? ????cout << "Median = " << findMedian(a, n) << endl;? ????return 0; } ```
                  <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>

                              哎呀哎呀视频在线观看