NOTE: It is recommended that you show what you have tried or attempted so far. Usually, a generic open question without any prior attempt gets down-voted. Since, you are beginner and am a lover of image processing, I couldn't help writing this code and posting this solution to help you get started.
As Paulpro commented, your problem is a low-pass filter implementation. In a given data matrix, you will have to find out the points which could be averaged through a 3 x 3 window. Hence, first I will explain how to identify these points. Please find a sample code with comments below which will explain the identification of these points.
// Input Data
int input_array[4][4] = { {10, 11, 1, 4}, {5, 1, 6, 9}, {9, 0, 2, 7}, {7, 4, 9, 8}};
// To calculate the average
float sum ;
// Row counter, column counter, dimension of the square matrix
int row_ctr, col_ctr, array_dimension;
int row, col;
array_dimension = 4; // Initialization
// Run the loop for the entire array
for(row_ctr = 0; row_ctr < array_dimension; row_ctr++)
{
// If the current row's top neighbor is outside the boundary or
// the bottom neighbor is outside the boundary, PASS and continue with
// next row
if(((row_ctr - 1) < 0) || ((row_ctr + 1) >= array_dimension))
{
continue;
}
// Run the loop for array dimension
for(col_ctr = 0; col_ctr < array_dimension; col_ctr++)
{
// If the current column's left neighbor is outside the boundary or
// right neighbor is outside the boundary, PASS and continue with
// next column
if(((col_ctr - 1) < 0) || ((col_ctr + 1) >= array_dimension))
{
continue;
}
// Initialize sum to 0.0
sum = 0.0;
// Reset to Top Left corner by going (-1, -1) from current position
row = row_ctr - 1;
col = col_ctr - 1;
sum = input_array[(row+0)][col] +
input_array[(row+0)][(col+1)]+ input_array[(row+0)][(col+2)];
sum += input_array[(row+1)][col] +
input_array[(row+1)][(col+1)]+ input_array[(row+1)][(col+2)];
sum += input_array[(row+2)][col] +
input_array[(row+2)][(col+1)]+ input_array[(row+2)][(col+2)];
// Find the average
sum = sum / 9.0;
printf("Average being found for (%d, %d) is %6.2f\n", row_ctr, col_ctr, sum);
}
}
When this code is executed the output would be displayed as
Average being found for (1, 1) is 5.00
Average being found for (1, 2) is 4.56
Average being found for (2, 1) is 4.78
Average being found for (2, 2) is 5.11