In: Computer Science
Write a function that dynamically allocates references to other arrays. The goal is to end up with a square 2D array who's value increment with each index increment so that the values placed in first array start at zero and end at 9, and the values placed in the last array start at 90 and end at 99.
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
code.cpp
#include <iostream>
using namespace std;
int main()
{
int **arrays;
arrays = new int*[10];
for(int i=0;i<10;i++){
arrays[i] = new int[10];
}
int counter=0;
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
arrays[i][j] =
counter;
counter++;
}
}
cout<<"Content of the array is
"<<endl;
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
cout<<arrays[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
output