g Given a 5 by 5 matrix of all positive values, write a program to find and display the greatest product of the 2 adjacent values in the vertical direction. For example, in the matrix below the greatest product of 2 adjacent values in vertical direction is 64 which is a product of mat(1,3) and mat(2,3).

Respuesta :

Answer:

Check the explanation

Explanation:

% iterate through each column (outer loop) , then iterate rows-1 (inner loop)

%take product of adjacent rows

mat = input('enter 5 by 5 matrix : ');

[R,C] = size(mat);

max_prod =0;

for c =[1:C]

for r=[1:(R-1)]

temp = mat(r,c)*mat((r+1),c);

if max_prod<temp

max_prod=temp;

end

end

end

fprintf('Greatest product : %i\n', max_prod)

Kindly check the output in the attached image below.

Ver imagen temmydbrain