i dont what is the problem in this simple program plz help distinguish prime numbers
Mostrar comentarios más antiguos
n=input ('the num ');
if n==1 ;
disp('the num is prime ')
break
else
for i=n:sqrt(n);
if rem(n,i)==0;
disp('the num is not prime ')
else
disp('the num is prime')
end
end
end
1 comentario
the cyclist
el 20 de Dic. de 2013
Editada: the cyclist
el 20 de Dic. de 2013
One side comment: 1 is not generally considered a prime. See, for example, http://en.wikipedia.org/wiki/Prime_number.
Respuesta aceptada
Más respuestas (1)
Sean de Wolski
el 20 de Dic. de 2013
if isprime(num)
disp('The num is prime')
else
disp('The num is not prime')
end
1 comentario
malek ebrahem
el 20 de Dic. de 2013
Categorías
Más información sobre Control Flow en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!