### C++ arrays question!

I have made my code to cout the average of the values without the k smallest and k highest. I have a question. Where it says "B' SKELOS" i want to make my code so it cout the average if it replaces the k highest and the k smallest values with their near values. Can you understand the question?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566`` ``````#include #include #include #include using namespace std; bool fthinousa(float n1, float n2) { return n1>n2; } bool au3ousa(float n1, float n2) { return n1> n >> k; float b[n], result1 = 0.f, result2 = 0.f; float array2[(n-k)]; float array3[(n-(2*k))]; for (int i=0; i> b[i]; } sort(b, b + n, au3ousa); for(int i=0; i
Understand: no.
What are near values?

You say that you now compute average of a set from which outliers have been removed. Do you want to compute average for whole set, but only after modifying some elements?
the near=for ex. 1 is near to 2, to near to 3.... do you now understand?
Do you mean, should k=2, that array
1, 2, 3, 4, 5
is replaced with
2, 3, 3, 3, 4
?

However, sum of elements and thus average remains the same. (+k-k==0)
k=2

array={1,2,3,4,5,6,7,8,9,10}

arrayafter={3,3,3,4,5,6,7,10,10,10}
std::sort( array, array+n );
auto sum = std::accumulate( array+k, array+n-k, 0 );
sum += k * (array[k] + array[n-k-1]);
auto avg = static_cast<double>( sum ) / n;
Topic archived. No new replies allowed.