Matlab code for Eratosthenes
显示 更早的评论
I wrote a code for the sieve of Eratosthenes, but the grader was not satisfied with my code. I'm not sure what I did wrong to his eyes. Any ideas? Please and thank you!
function p = prime_seive(n)
p = [0 2:n];
for k = 2:sqrt(n)
if p(k)
p(k^2:k:n) = 0;
end
end
p = p(p ~= 0);
end
5 个评论
Aaron Millan
2021-4-29
Aaron Millan
2021-4-29
Krystian
2024-10-21
maybe the wrong spelling of "sieve" in the function's name?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Manage Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!