Hello everyone, I would like to write a function to find the prime number from 0 to n . I would apreciate your help!
显示 更早的评论
3 5 7......n
5 个评论
Walter Roberson
2012-9-4
1 is not a prime number.
nawal shaikh
2012-9-4
Honglei Chen
2012-9-4
but 2 should be
Walter Roberson
2012-9-5
(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
2012-9-5
I think my answer here should do:
回答(2 个)
Matt Fig
2012-9-4
p = @(n) primes(n);
2 个评论
nawal shaikh
2012-9-4
Honglei Chen
2012-9-4
you can take a peek at the primes function
edit primes
Jan
2012-9-4
0 个投票
Look in the internet for "sieve of Eratosthenes". You will find smart algorithms which can be implemented in Matlab directly.
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!