prime number.there isn't any error. my ans isn't showed up
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kashfia Mahin
el 2 de Nov. de 2018
Comentada: Kashfia Mahin
el 3 de Nov. de 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 comentarios
Guillaume
el 2 de Nov. de 2018
People attach all sort of weird tags to their question. I've removed the tag.
Walter Roberson
el 2 de Nov. de 2018
Respuesta aceptada
Bruno Luong
el 2 de Nov. de 2018
Editada: Bruno Luong
el 2 de Nov. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!