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

8 views (last 30 days)
hasann sinji
hasann sinji on 9 Nov 2021
Answered: Benjamin on 9 Nov 2021
%prime numbers between 2 and 100

Answers (1)

Benjamin 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;

Community Treasure Hunt

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

Start Hunting!