Question: Fill in the code for the function only using for loops You are given an nxn array of integers. Let us call this array grid.
You are given an nxn array of integers. Let us call this array grid. All the elements of grid are either 0 or 1 Write a function (name the function neighbors) that will take as arguments only two integer indices i,j, and wil return the number of nonzero entries of the array grid that are adjacent to the i-th, j-th element of the array. For example, if the grid array is the 7x7 array shown below, then your function should return the following values, when called with the arguments shown below: 0th 52d3"d4t5th6th column column column colu mn column colmn column row row row row row row neighbors(0,0) should return 0, since there are no non-zero neighbors to element (0,0) neighbors(0,1) should return 1, since there is 1 non-zero neighbor to element (0,1) neighbors(3,3) should return 4, since there are 4 non-zero neighbors to element (3.3) neighbors (3,4) should return 2, neighbors(5,3) should return 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
