Here is a C ++ solution for your job, but you probably wonβt be allowed to pass this :-)
#include <algorithm> #include <functional> #include <iostream> #include <iterator> #include <numeric> int main() { const int N = 10; int ary[N] = {4, 32, 9, 7, 14, 12, 13, 17, 19, 18}; int max = *std::max_element(ary, ary + N); std::cout << "maximum: " << max << std::endl; double average = std::accumulate(ary, ary + N, 0.0) / N; std::cout << "average: " << average << std::endl; std::cout << "outlier: "; std::remove_copy_if(ary, ary + N, std::ostream_iterator<int>(std::cout, " "), std::bind2nd(std::less_equal<double>(), 2 * average)); std::cout << std::endl; }
fredoverflow
source share