Create a script file using control flow statements that returns all the prime numbers from 2 till hundred.

5 visualizaciones (últimos 30 días)
%prime numbers between 2 and 100

Respuestas (1)

Voss
Voss el 9 de Nov. de 2021
This solution does not use any control flow statements:
numbers = 3:100;
prime_numbers = numbers(isprime(numbers));
This solution does use control flow statements:
prime_numbers = [];
for i = 3:100
if isprime(i)
prime_numbers(end+1) = i;
end
end

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by