Something like this will find the first closest and farthest values from average:

Code:

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int numbers[] = {1,2,3,4,5,6,7,8,9};
int sum = 0;
int avg;
int i;
for ( i = 0; i < 9; i++ )
sum += numbers[i];
avg = sum / 9;
cout<<"Average: "<< avg <<'\n';
int closest = numbers[0];
int farthest = numbers[0];
for ( i = 1; i < 9; i++ ) {
if ( abs ( avg - numbers[i] ) < abs ( avg - closest ) )
closest = numbers[i];
if ( abs ( avg - numbers[i] ) > abs ( avg - farthest ) )
farthest = numbers[i];
}
cout<<"First closest to average: "<< closest <<'\n';
cout<<"First farthest from average: "<< farthest <<endl;
}

[edit]

I'm too slow I suppose.

[/edit]