i dont what is the problem in this simple program plz help distinguish prime numbers
Ältere Kommentare anzeigen
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 Kommentar
the cyclist
am 20 Dez. 2013
Bearbeitet: the cyclist
am 20 Dez. 2013
One side comment: 1 is not generally considered a prime. See, for example, http://en.wikipedia.org/wiki/Prime_number.
Akzeptierte Antwort
Weitere Antworten (1)
Sean de Wolski
am 20 Dez. 2013
if isprime(num)
disp('The num is prime')
else
disp('The num is not prime')
end
1 Kommentar
malek ebrahem
am 20 Dez. 2013
Kategorien
Mehr zu Control Flow finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!