trying to display a list of numbers

2 次查看(过去 30 天)
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

采纳的回答

Ameer Hamza
Ameer Hamza 2020-9-23
编辑:Ameer Hamza 2020-9-23

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by