How do I write a function to find 4 consecutive numbers in a square matrix which would give the largest product?
1 view (last 30 days)
Show older comments
I think I should be using for loops but I'm very confused how to write them in this case.
function y=hardstuff(a)
x=size(a)
if x(1)~=x(2)
error 'Matrix not square'
elseif x(1)<=3
error 'Matrix too small'
end
b=a(1,:)
c=length(b)
d=1
for i=1:4
d=d*a(i)
end
1 Comment
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!