Hello everyone, I would like to write a function to find the prime number from 0 to n . I would apreciate your help!
Show older comments
3 5 7......n
5 Comments
Walter Roberson
on 4 Sep 2012
1 is not a prime number.
nawal shaikh
on 4 Sep 2012
Honglei Chen
on 4 Sep 2012
but 2 should be
Walter Roberson
on 5 Sep 2012
(Volunteers, please do not post complete code for this question, as it is an introductory programming question designed to help people learn how to think about programming. Making mistakes and learning how to debug is an important part of this task that would not be learned if code is given.)
Sean de Wolski
on 5 Sep 2012
I think my answer here should do:
Answers (2)
Matt Fig
on 4 Sep 2012
p = @(n) primes(n);
2 Comments
nawal shaikh
on 4 Sep 2012
Honglei Chen
on 4 Sep 2012
you can take a peek at the primes function
edit primes
Jan
on 4 Sep 2012
0 votes
Look in the internet for "sieve of Eratosthenes". You will find smart algorithms which can be implemented in Matlab directly.
Categories
Find more on Performance and Memory 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!