#include<iostream>
#include<cmath>
int main()
{
int b[4][4]; // unused variable
int a[4][4]; // 16 elements
int r=0, i=0, j=0, x=0, y=0;
for ( i=0; i<=4 ;i++) // this uses 0-4. Five values. a has only four: 0-3
{
for(j=0;j<=4;j++) // this uses 0-4. Five values. a has only four: 0-3
cin >> a[i][j]; // you read 25 elements. Out of range error.
}
{
for ( i=1; i<4; i++) // this uses 1-3
{
for ( j=1; j<4; j++) // this uses 1-3
r = (a[i+1][j] + a[i-1][j] + a[i][j+1] + a[i][j-1] + a[i][j]) / 5; // calculated 9 times.
// 4 is an invalid index. Out of range error.
// integer division discards remainder, i.e. 4/5 == 0
// These happen only within the outer loop; three times
//r++;
a[i][j]=r;
cout<<" " << a[i][j]<<" ";
}
}
return 0;
}