Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- // CONSTANTS
- const int COL = 2;
- // Variable Declaration
- int numElements1D;
- int numElements2D;
- int* ptr1D;
- int** ptr2D;
- cout << "Enter number of elements for 1D array: ";
- cin >> numElements1D;
- cin.clear();
- cin.ignore(10000, '\n');
- if (numElements1D <= 0)
- ptr1D = new int[1];
- else
- ptr1D = new int[numElements1D];
- // Fill 1D array
- fill1dArray(ptr1D, numElements1D);
- cout << endl;
- //2D ARRAY
- cout << "Enter number of elements for 2D array: ";
- cin >> numElements2D;
- cin.clear();
- cin.ignore(10000, '\n');
- // Calc number of rows based on number of elements
- if (numElements2D <= 0)
- numElements2D = 1;
- else if (numElements2D % 2 == 0)
- numElements2D /= 2;
- else
- {
- numElements2D++;
- numElements2D /= 2;
- }
- //Creates the row of the 2D array
- ptr2D = new int*[numElements2D];
- // Creates the columns of the array
- for (int row = 0; row < numElements2D; row++)
- ptr2D[row] = new int[COL];
- // Nested Loop to insert numbers into 2D array
- fill2dArray(ptr2D, numElements2D);
- print1D(ptr1D, numElements1D);
- print2D(ptr2D, numElements2D);
- delete[] ptr1D;
- delete[] ptr2D;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement