How to show non prime numbers (what is the contrari function of prime?)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Toni Clares
el 9 de Oct. de 2016
Editada: Walter Roberson
el 9 de Oct. de 2016
clc
clear all
n=input('number') % Natural number that you want to know if it a prime number
i=2;
x=[];
if n==0 | n==1
disp('there are not prime numbers');
end
while i<=sqrt(n)
if rem(n,i)==0 %In this part i want to show the non prime numbers (i don't know the function name)
x=n
else %In this part i show the prime numbers
y=primes(n)
break
end
i=i+1;
end
fid=fopen('Prime_numbers.txt','w'); %In this final part i create a .txt document for save the prime
fprintf(fid,'%2d\t%2g\t',y);
fclose(fid);
fid=fopen('Non_prime_numbers.txt','w'); %In this final part i create a .txt document for save the non prime
fprintf(fid,'%2d\t%2g\t',x);
fclose(fid);
0 comentarios
Respuesta aceptada
Walter Roberson
el 9 de Oct. de 2016
You could use setdiff() of the range of values, asking to remove the primes.
2 comentarios
Toni Clares
el 9 de Oct. de 2016
Editada: Walter Roberson
el 9 de Oct. de 2016
Toni Clares
el 9 de Oct. de 2016
Editada: Walter Roberson
el 9 de Oct. de 2016
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!