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 Center および File ExchangeLine Plots についてさらに検索

タグ

タグが未入力です。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by