# I have a mistake in loops

2 views (last 30 days)

Show older comments

Hello, I have somewhere a mistake that if N = 1000 the output misses some lines (don't know which), so I suppose there's a mistake somewhere in for loops. It works correctly with N = 50, 100, 500.

function [R, I] = problem2B(N)

I = 0;

for a = 3:N

for b = a:N

for c = b:N

if (a^2 + b^2) == c^2 && a+b+c < N

R(I+1, :) = [a+b+c, a, b, c];

I = I + 1;

elseif N < 12

R = zeros(4, 1);

end

end

end

end

if N <= 50

R = reshape(nonzeros(R), I, 4);

else

R = sortrows(R, 1);

end

end

### Accepted Answer

Steven Lord
on 5 Nov 2021

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!