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

5 views (last 30 days)
%prime numbers between 2 and 100

Answers (1)

Voss
Voss on 9 Nov 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

Categories

Find more on Loops and Conditional Statements 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!