Complete the code to return the first even number from the array.
int first_even(int arr[], int size) {
for (int i = 0; i < size; i++) {
if (arr[i] % 2 == 0) {
return [1];
}
}
return -1;
}The function returns the first even number found in the array, so it should return arr[i].
Complete the code to return the index of the first negative number in the array.
int first_negative_index(int arr[], int size) {
for (int i = 0; i < size; i++) {
if (arr[i] < 0) {
return [1];
}
}
return -1;
}The function should return the index where the first negative number is found, so it returns i.
Fix the error in the code to return the sum of positive numbers, stopping early if a zero is found.
int sum_positive(int arr[], int size) {
int sum = 0;
for (int i = 0; i < size; i++) {
if (arr[i] == 0) {
[1];
}
if (arr[i] > 0) {
sum += arr[i];
}
}
return sum;
}When zero is found, the function should return the current sum immediately, so use return sum;.
Fill both blanks to return the first number greater than 10 and its index.
int* first_greater_than_ten(int arr[], int size) {
static int result[2];
for (int i = 0; i < size; i++) {
if (arr[i] [1] 10) {
result[0] = arr[i];
result[1] = [2];
return result;
}
}
return NULL;
}The condition should check if the number is greater than 10 using >, and the index i is stored as the second element.
Fill all three blanks to return the first negative number, its index, and stop the loop.
int find_negative(int arr[], int size, int *index) {
for (int i = 0; i < size; i++) {
if (arr[i] [1] 0) {
*index = [2];
[3] arr[i];
}
}
*index = -1;
return 0;
}The condition checks if the number is less than zero using <. The index is set to i, and the function returns the found negative number immediately with return.