Two Dimensional Array
Can any one help me how to pass a two dimensional array.I have written the program.
Thanks
----------------------
#include <iostream>
#include <string>
int read();
void createMatrix(int);
int drawTree(int, double[][]);
int main()
{
read();
return 0;
}
int read()
{
int input = 0; // no of sequences
//int seqLen = 0; // length of sequence
//int seqSame = 0;
int totalClusters = 0;
cout << "Enter The Number Of Sequences : ";
// keeps on going till an integer is entered
while(!(cin >> input))
{
string buffer;
cin.clear(); //clear failbit
cin >> buffer; //flush stream
cout << "Invalid Input.. Please Enter An Interger Only !!!" << endl;
cout << "Enter The Number Of Sequence : ";
}
// total clusters
totalClusters = input ;
// initialise matrix
createMatrix(totalClusters);
return 0;
}
void createMatrix(int totalClusters)
{
double matrix [totalClusters][totalClusters];
// initialise matrix with 0
for (int i = 0; i < totalClusters; i++)
{
for (int j = 0; j < totalClusters; j++)
{
matrix[i][j] = 0;
}// inner 2nd
} //outer most
// display matrix
for (int m = 0; m < totalClusters ; m++)
{
for (int n = 0; n < totalClusters ; n++)
{
cout << " " << matrix[m][n];
}
//next line
cout << "\n";
}
// pass by reference matrix
drawTree(totalClusters,matrix);
}
int drawTree(int totalClusters, double newMatrix[][])
{
cout << "Inside the proc " << endl;
// display matrix
for (int i = 0; i < totalClusters ; i++)
{
for (int j = 0; j < totalClusters ; j++)
{
cout << " " << newMatrix[i][j];
}
//next line
cout << "\n";
}
}
----------

