Thread: Find last largest integer in array?

1. Find last largest integer in array?

I am having trouble writing code that will print the last index of the last largest integer an a array. I can get it to print the first index of the largest but if I have two of the largest number in the array I want it to print the last index of the largest and not the first.

I am searching a table but the code really pertains to an array that is within a for loop.

What I am looking to get is the following. If a certain row in the table is 10 10 10 10 10 I would like it to print the last index 4 and not 0.

Thanks,
Cameron

Code:
```#include "mystuff.h"

int findlastlarge(int** table, int numrows, int numcols)

{
// local declarations
int i;
int j;
int large;

// print title
printf("g. The various last indices of the largest int for each and every row is:\n");

// finds the odd values in each row
for (j = 0; j < numrows; j++)
{
int largest = INT_MIN;

for (i = 0; i < numcols; i++)
{
if (table[j][i] > largest)
{
largest = table[j][i];
large = i;
}
}
printf("    %d\n", large);
}
}```

2. Code:
```if (table[j][i] > largest)
{
largest = table[j][i];
large = i;
}```
So if all the numbers in the row were 10 (10 10 10 10 10 as per your example), then the bit of code in red would never get executed after the first run through. You will need to add an extra test in there to allow for numbers of the same size, so that the large variable will be incremented accordingly, even though the largest variable might stay the same.

3. I ended up using = and it works perfect.

if (table[j][i] >= largest)
{
largest = table[j][i];
large = i;
}