i dont what is the problem in this simple program plz help distinguish prime numbers
Show older comments
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 Comment
the cyclist
on 20 Dec 2013
Edited: the cyclist
on 20 Dec 2013
One side comment: 1 is not generally considered a prime. See, for example, http://en.wikipedia.org/wiki/Prime_number.
Accepted Answer
More Answers (1)
Sean de Wolski
on 20 Dec 2013
if isprime(num)
disp('The num is prime')
else
disp('The num is not prime')
end
1 Comment
malek ebrahem
on 20 Dec 2013
Categories
Find more on Control Flow in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!