trying to display a list of numbers

2 views (last 30 days)
I am trying to display a list of numbers of prime numbers from 1-1000. I tried using a for loop and if else statements.
for n=1:1000
if rem(n,2) == 0
disp('Not a prime number')
elseif rem(n,3) == 0
disp('Not a prime number')
elseif rem(n,5) == 0
disp('Not a prime number')
elseif rem(n,7) == 0
disp('Not a prime number')
elseif rem(n,11) == 0
disp(num2str(n))
end
end

Accepted Answer

Ameer Hamza
Ameer Hamza on 23 Sep 2020
Edited: Ameer Hamza on 23 Sep 2020

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices 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!