I need to write a code to find numbers divisible by 7 and multiples of 5 from 1500:2700. How do I preallocate line 4 for speed and is my code the most efficient way to solve
result = [];
for num = 1500:2700
if mod(num, 7) == 0 && mod(num, 5) == 0
result = [result, num];
end
end
disp(‘Numbers between 1500 and 2700 that are divisible by 7 and multiples of 5:’);
disp(result);result = [];
for num = 1500:2700
if mod(num, 7) == 0 && mod(num, 5) == 0
result = [result, num];
end
end
disp(‘Numbers between 1500 and 2700 that are divisible by 7 and multiples of 5:’);
disp(result); result = [];
for num = 1500:2700
if mod(num, 7) == 0 && mod(num, 5) == 0
result = [result, num];
end
end
disp(‘Numbers between 1500 and 2700 that are divisible by 7 and multiples of 5:’);
disp(result); hw MATLAB Answers — New Questions