prime number.there isn't any error. my ans isn't showed up
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kashfia Mahin
am 2 Nov. 2018
Kommentiert: Kashfia Mahin
am 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 Kommentare
Guillaume
am 2 Nov. 2018
People attach all sort of weird tags to their question. I've removed the tag.
Akzeptierte Antwort
Bruno Luong
am 2 Nov. 2018
Bearbeitet: Bruno Luong
am 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Number Theory finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!