Programs of Loops
Find prime numbers and traverse lists in a circular manner.
We'll cover the following
Store the first n
prime numbers in the array
The following program stores the first n
prime numbers in an array. The value of n
is chosen by the user, and any number can be used. Here’s how to solve this problem:

Start with an empty array of
n
elements. 
Store $2$ as the first prime number at the $0^{th}$ index.

Keep checking every following integer by dividing it by every prime value in the array.

Check $3$ by taking the remainder after dividing it by all the prime values in the array. The only value in the current array is $2$. Since the remainder is nonzero, $3$ is stored in the array.

Then, check $4$ in the same way. Since the remainder of $4$ divided by $2$ is $0$, it’s not stored in the array.

Get handson with 1200+ tech skills courses.