I am able to extract list of prime numbers but when list has negative numbers, or 0 or 1 the condition doesn't work. Please help me fix the bug in this code. Detailed step by step explaination for putting the condition is encouraged . Thank you
clear
clc
%Matlab program to give prime numbers in a given interval Ignoring 0, 1 and negative numbers if in the input range
start = input('Enter a starting number range:');
end_point = input('enter an ending number:');
list = start:end_point; % Create a list having the range
prime = []; % initiate empty prime vector, prime numbers will be added to this list
for i = (1:length(list))
fac = 0; % calculates the number of factors
if list(i) <= 1 %Checks whether the number is less than or equal to 1
fac = fac+1 % Assigns factor 1 and hence the algorithm ignores them from prime list
break
for j = 2:list(i)/2
if list(i) <= 1 %Checks whether the number is less than or equal to 1
fac = fac+1 % Assigns factor 1 and hence the algorithm ignores them from prime list
break
% if j == []
% fac = fac + 1
% break
elseif mod(list(i),j) == 0 % checks whether a number is prime or not from the list
fac = fac+1;
else
fac = fac+0;
end
end
if fac <1 % No factors between 2 and number\_checked/2 hence puts it in prime list
prime = [prime,list(i)];
else
continue
end
end