### Passing one row from a multidimensional array into a function .

So I have a multidimensional array like this ,

N is any integer value
`double arrayDistances[N][N+1];`

every row of the multidimensional array consists of a number of doubles
and I have wrote a function to calculate the largest one .
 ``1234567891011`` ``````double theLargest(double d[], int n){//takes an array of doubles as an argument also takes n number of elements double largest = d[0]; for(int i = 0 ; i largest){ largest = d[i]; } } return largest; }``````

My question is how I can pass one row at a time from the multidimensional array and find the largest from that one row and store into some other array like this .

`double largestFromEach[N];`
Last edited on
 ``1234567891011`` ``````void theLargest(double **d, double largestFromEach[], int n){ for(int j = 0;j < n;j++){ largestFromEach[j] = d[i][0]; for(int i = 1 ; i < n ; i++) if(d[j][i] > largestFromEach[j]) largestFromEach[j] = d[j][i]; }}``````

Find the largest value :
 ``1234567`` ``````double theLargestValue(double largestFromEach[], int n) { double largest = largestFromEach[0]; for(int i = 1 ; i < n ; i++) if(largestFromEach[j] > largest)largest = largestFromEach[j]; return largest; }``````

This is the example code. Need more details? If you need help just ask.
Last edited on
Thanks,
I figured this way out ,

 ``1234`` `````` double largestFromEach[N]; for(int i = 0 ; i < N ; i++){ largestFromEach[i] = theLargest(assDistances[i], N+1); }``````

and it works fine.
Thanks for the help
Topic archived. No new replies allowed.