Monday, October 6, 2008

Passing 2D array To a Function in c++

#include



void Fill (int ** A, unsigned rows, unsigned cols, int val);


int main() {
int i;

int R, C; // size of the array in rows and columns
cout << "Please enter the size of the array in rows and columns\n"
<< "rows=";
cin>> R;
cout<< "cols=";
cin>> C;

int ** A;
A= new int* [R];
for (i=0; i A[i]= new int [C];

/// ACTUALLY A IS NOW 2D Array


Fill(A, R, C, 5);

;
cout<<"\n"< A[5][6]=5;

return(0);
}



void Fill (int ** A, unsigned rows, unsigned cols, int val) {
for (unsigned i=0; i for (unsigned j=0; j A[i][j]=i*j;// You Can Use "val" varible
}



No comments:

Just Answer


JustAnswer.com