我需要编写一个C++代码,找到一个数组的中位数和众数。有人告诉我,在对数字进行排序之后查找数组的众数要容易得多。我已经对函数进行了排序,但仍然无法找到众数。
int counter = 0;
for (int pass = 0; pass < size - 1; pass++)
for (int count = pass + 1; count < size; count++) {
if (array [count] == array [pass])
counter++;
cout << "The mode is: " << counter << endl;
counter
不是众数。查看这里 众数。 - gongzhitaao