Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Matlab code for finding prime numbers

조회 수: 7 (최근 30일)
Aaron Millan
Aaron Millan 2021년 4월 29일
마감: Stephen23 2021년 4월 29일
I wrote a code for the sieve of erasthosenes (a way to find and arrange all the prime numbers before a user-defined value, "n", both by dividing the numbers by all the pervious numbers, and by only going up to the square root of n), 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

답변 (0개)

이 질문은 마감되었습니다.

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by