Prime Number Arrays

I Want code for this question in c++...

Write a C++ program in which declare 2D integer array of size 20x20, take inputs for the size of
matrix to use and take values for that size. Store the prime numbers of matrix in 1D array and display.

Help me in this problem.....
creating a matrixint matrix[rows][cols];
traversing a matrix
1
2
3
for(int K=0; K<rows; ++K)
   for(int L=0; L<cols; ++L)
      //operate on cell matrix[K][L] 

check if a number is prime (pseudocode)
1
2
3
4
5
6
7
def isprime(n):
   for(p in primes)
      if p*p > n:
         break
      if n%p==0:
         return false
  return true
here `primes' is the list of prime numbers, if you don't want to maintain that you may use
a_0 = 2, a_1 = 3, a_k = a_{k-1}+2
(odd numbers and 2)
ThankYou ne555 (9452) I will Try......
Topic archived. No new replies allowed.