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!