I want to find the index of the last element containing an even number in an array, A, with 'length' number of elements.
For example, for A = {1, 2, 4, 5, 7}
we would return 2 as the value 4 is the last even number and it is at index 2 in the array.
I am required to use a for loop where the fewest number of elements need to be tested, where the first line follows the format:
for ( i = ??; i > ??; i = ??)
I think there's something wrong with the first line of my code but I don't know how to fix it.
for ( i = length-1; i >= 0; i = i-1) {
if ( A[i] % 2 == 0) { // value mod 2 = 0 indicates even
return i;
}
error: subscripted value is neither array nor pointer nor vector
'if (A[i]% 2==0) { // value mod 2 = 0 indicates even'