trying to display a list of numbers
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Maria Galle
 el 23 de Sept. de 2020
  
    
    
    
    
    Editada: Ameer Hamza
      
      
 el 23 de Sept. de 2020
            I am trying to display a list of numbers of prime numbers from 1-1000. I tried using a for loop and if else statements.
for n=1:1000
    if rem(n,2) == 0
        disp('Not a prime number')
    elseif rem(n,3) == 0
        disp('Not a prime number')
    elseif rem(n,5) == 0
        disp('Not a prime number')
    elseif rem(n,7) == 0
        disp('Not a prime number')
    elseif rem(n,11) == 0
        disp(num2str(n))
    end
end
0 comentarios
Respuesta aceptada
  Ameer Hamza
      
      
 el 23 de Sept. de 2020
        
      Editada: Ameer Hamza
      
      
 el 23 de Sept. de 2020
  
      Why not
primes(1000)
For an alternative solutions, check the code here: https://www.mathworks.com/matlabcentral/fileexchange/32774-this-program-finds-prime-numbers-manually 
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Data Import and Analysis 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!

