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

4 vues (au cours des 30 derniers jours)
Kashfia Mahin
Kashfia Mahin le 2 Nov 2018
Commenté : Kashfia Mahin le 3 Nov 2018
% 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 commentaires
Guillaume
Guillaume le 2 Nov 2018
People attach all sort of weird tags to their question. I've removed the tag.

Connectez-vous pour commenter.

Réponse acceptée

Bruno Luong
Bruno Luong le 2 Nov 2018
Modifié(e) : Bruno Luong le 2 Nov 2018
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

Plus de réponses (0)

Tags

Aucun tag saisi pour le moment.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by