Question:
Write a program that creates a two-dimensional array initialized with test data. Use any data type you wish. Declare a two-dimensional array of data type char, int, double, or string. Assume the array is declared as follows:
const int NUM_ROWS = 3, NUM_COLUMNS = 5;
test data: [10, 1, 1, 1, 1] [7, 2, 20, 2, 9] [ 3, 3, 3, 3, 5]
Answer:
The program in C++ is as follows:
#include<iostream>
using namespace std;
int main(){
const int NUM_ROWS = 3, NUM_COLUMNS = 5;
int MyArray[NUM_ROWS][NUM_COLUMNS] = {{10, 1, 1, 1, 1},{7, 2, 20, 2, 9},{3, 3, 3, 3, 5}};
return 0;
}
Step-by-step explanation:
To answer this question, we make use of the following parameters
Array name: MyArray
Array datatype: integer
The explanation is as follows:
This declares the array dimensions
const int NUM_ROWS = 3, NUM_COLUMNS = 5;
This declares and initializes the array with the test data
int MyArray[NUM_ROWS][NUM_COLUMNS] = {{10, 1, 1, 1, 1}, {7, 2, 20, 2, 9}, {3, 3, 3, 3, 5}};