Removing a number from array without changing its arithmetic mean | CPP program to remove a number from the array without changing its arithmetic mean ; Function to remove a number from the array without changing its arithmetic mean ; Find sum of all elements ; If mean is an integer ; Check if mean is present in the array or not ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int FindElement ( int a [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + a [ i ] ; if ( sum % n == 0 ) { int m = sum / n ; for ( int i = 0 ; i < n ; i ++ ) if ( a [ i ] == m ) return m ; } return -1 ; } int main ( ) { int a [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof ( a ) / sizeof ( int ) ; cout << FindElement ( a , n ) ; return 0 ; }