0
Let array =[1, 2,3,4,5,6,7,8,9,10] how get prime numbers from this array
I want only prime numbers using for loop
5 Respuestas
+ 2
Padala Bala Sirisha
You have to check array value but you are checking iteration value 'i'
if (array[i] % 3 == 0)
+ 2
Drop 1
Now
As long as array is not empty
First value of array f is a prime
Drop all elements that a devisible by f, also f
+ 1
Padala Bala Sirisha
Iterate array using for loop and get reminder of each element. If reminder is 0 then print that element
0
I don't get it
0
Padala Bala Sirisha Checking if a number is prime is a very frequently answered question, here, there, and everywhere. Just search for codes and other questions to see how it can be done.
Just make sure you understand how to get the remainder of an integer division. It's way too easy, but mandatory.
Then, loop thru array items and test each one. Or use filter functions. Or whatever suits best.
But don't wait. Start in Code Playground, link the code in the question description, and bring your difficulties here.