Question: Write a C function which returns the number of even values in an array. Place your answer in a file named count_even_function.c Your function should

Write a C function which returns the number of even values in an array.

Place your answer in a file named count_even_function.c

Your function should take two parameters: the length of the array, and the array. It must have this prototype:

int count_even(int length, int array[length]); 

Your function should return a single integer: the number of even values in the array.

For example if the array contains these 8 elements:

16, 7, 8, 12, 13, 19, 21, 12 

Your function should return `4`, because these 4 elements are even:

16, 8, 12, 12 

Assumptions/Restrictions/Clarifications.

An even number is divisible by 2.

Your function should return a single integer.

Your function should not change the array it is given.

Your function should not call scanf (or getchar or fgets).

You can assume the array only contains positive integers.

You can assume the array contains at least one integer.

Your function should not print anything. It should not call printf.

Your submitted file may contain a main function. It will not be tested or marked.

Starting Code

Here is some code you can use to start this question.

#include  #include  // return the number of even values in an array. int count_even(int length, int array[]) { // PUT YOUR CODE HERE (you must change the next line!) return 42; } // This is a simple main function which could be used // to test your count_even function. // It will not be marked. // Only your count_even function will be marked. # define TEST_ARRAY_SIZE 8 int main(void) { int test_array[TEST_ARRAY_SIZE] = {16, 7, 8, 12, 13, 19, 21, 12}; int result = count_even(TEST_ARRAY_SIZE, test_array); printf("%d ", result); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!