Add a function that will accept the 2D array and the rows andcolumns specified b
ID: 3614914 • Letter: A
Question
Add a function that will accept the 2D array and the rows andcolumns specified by the user then fill the array so that eachnumber in the array is (2 * the row index) plus (3 * the columnindex). For example a 3 by 4 matrix would look like
0 3 6 9
2 5 8 11
4 7 10 13
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int rows, cols;
cout<<"Please enter thedimensions of the 2D array."<<endl;
cout<<"Please enter the numberof rows you want to use"<<endl;
cin>>rows;
while(rows <= 0 || rows >20)
{
cout<<"The number of rows must be greater than 0 and lessthan or equal to 20"<<endl;
cout<<"Please enter the number of rows you want touse"<<endl;
cin>>rows;
}
cout<<"Please enter the numberof columns you want to use"<<endl;
cin>>cols;
while(cols <= 0 || cols >15)
{
cout<<"The number of rows must be greater than 0 and lessthan or equal to 15"<<endl;
cout<<"Please enter the number of rows you want touse"<<endl;
cin>>cols;
}
return 0;
}
void Print2DArray(intarr1[][15], int r, int c)
{
int i = 0, j;
while (i < r)
{
j = 0;
while (j < c)
{
cout<<setw(5)<<arr1[i][j];
j++;
}
cout<<endl;
i++;
}
}
Explanation / Answer
please rate - thanks #include #include using namespace std; void fill(int[][15],int,int); void Print2DArray(int[][15],int,int); int main() { int rows, cols,a[20][15]; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.