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 .
1
2
3
4
5
6
7
8
9
10
11
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<n ; i++){
        if(d[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
1
2
3
4
5
6
7
8
9
10
11
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 :
1
2
3
4
5
6
7
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 ,

1
2
3
4
    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.