Prime Numbers (Two dimensional array using pointers)

Hello,

I am trying to write a C++ program that reads the number of rows and columns of a 2d array and initializes row by row the array with the first prime numbers in increasing order. Using indexes.

This is what I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

int main ()
{
	int rows,columns;
	cout<<"Enter number of rows"<<endl;
	cin>>rows;
	cout<<"Enter the number of columns"<<endl;
	cin>>columns;

double **A=new double *[rows];
int primenums, n ;
for (int i=2;i<=rows;++i )
	primenums[i] = 1;
for (int i=2; i<=n/2; ++i )
            for ( int j=2; i*j<=rows; ++j )
                   primenums[i*j] = 0;


Any guidance is appreciated. I know i am way off on the code but advice on how to go about it would be very helpful.
Why a 2d array? Is that required by the assignment?
Yes the assigment requires a program that "reads from the keyboard the number of rows and columns of a 2d array"

I think this is the case since it also asks to "address the elements and the rows of the array using indexes."
I have started from scratch as my first code was very hard to follow.
This is the new code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

int main ()
{
   int rows;
   int columns;
   cout<<"enter no. of rows"<<endl;
   cin>>rows;
   cout<<"enter no. of columns"<<endl;
   cin>>columns;
   int **A=new int *[rows][columns];
 
   for(int i = 0; i< rows; i++)
   {
           A[i] = new int[rows];
   }
   for (int i = 0; i < rows; i++)
        for(int j =0; j<columns; j++)
   

}
   return 0;
Topic archived. No new replies allowed.