prime number.there isn't any error. my ans isn't showed up

조회 수: 2 (최근 30일)
Kashfia Mahin
Kashfia Mahin 2018년 11월 2일
댓글: Kashfia Mahin 2018년 11월 3일
% finding prime number
counter=0;
for j= 1:10;
for i=1:1:j
if mod (j,i)==0
counter=counter+1;
end
end
if counter==2
fprintf('%d is prime', j);
end
end
there isn't any error. my ans isn't showed up
  댓글 수: 3
Guillaume
Guillaume 2018년 11월 2일
People attach all sort of weird tags to their question. I've removed the tag.

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2018년 11월 2일
편집: Bruno Luong 2018년 11월 2일
There is actually one error (where counter is reset)
for j= 1:10
counter=0; % <- reset for every i to be checked
for i=1:1:j
if mod (j,i)==0
counter=counter+1;
end
end
if counter==2
fprintf('%d is prime\n', j);
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by