You must time the test yourself and ensure you comply with the conditions below.
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
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.
#include <stdio.h>
#include <stdlib.h>
// 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\n", result);
return 0;
}
When you think your program is working you can autotest
to run some simple automated tests:
1511 autotest count_even_function
give cs1511 test07_count_even_function count_even_function.c
Place your answer in a file named remove_duplicates_function.c
Your function should take three parameters: the length of source array, the source array itself, and the destination array. It must have this prototype:
int remove_duplicates(int length, int source[length], int destination[length]);
Your function should return a single integer: the number of elements copied to the destination array.
For example if the source array contains these 8 elements:
3, 1, 4, 1, 5, 9
Your function should copy these 5 values to the destination array:
3, 1, 4, 5, 9
Your function should return the integer 5, because there were 5 values copied -- the second occurrence of the digit 1 was not copied.
You can assume the source array contains at least one integer.
You can assume that the destination array will always be large enough to fit all of the copied values.
You cannot assume anything about the number of duplicates, i.e. there may not be any duplicates, or conversely, the entire array may be duplicates.
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).
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.
When you think your program is working you can autotest
to run some simple automated tests:
1511 autotest remove_duplicates_function
give cs1511 test07_remove_duplicates_function remove_duplicates_function.c
It should then print the most frequently occurring integer.
If there is a tie for the most frequent integer, your program should print the largest integer that is tied for most frequent.
Match the the example below EXACTLY.
./most_frequent_integer 1 1 2 3 5 1Explanation: given the input 1 1 2 3 5, your program should print 1, as this was the most frequently occurring integer -- it appeared twice.
./most_frequent_integer 655 10 204 8192 76 38 204 43912 204 204Explanation: given the input 655 10 204 8192 76 38 204 43912 204, your program should print 204, as this was the most frequently occurring integer -- it appeared 3 times.
./most_frequent_integer 1 2 1 2 1 2 2Explanation: given the input 1 2 1 2 1 2, your program should print 2, as this is the largest most frequently occurring integer -- both 1 and 2 appeared three times, and 2 is the largest value.
You can assume each line will contain one and only one integer.
You can assume your input contains at least one integer.
You can assume your input contains no more than 100,000 integers.
You are free to write this program in any way you wish: there is no specific function that you need to implement. Note that your program will need to have a `main` function.
When you think your program is working you can autotest
to run some simple automated tests:
1511 autotest most_frequent_integer
give cs1511 test07_most_frequent_integer most_frequent_integer.c
You can run give multiple times. Only your last submission will be marked.
Don't submit any exercises you haven't attempted.
If you are working at home, you may find it more convenient to upload your work via give's web interface.
Remember you have until Wednesday 25 April 23:59:59 to complete this test.
Automarking will be run several days after the submission deadline for the test. When complete you can view automarking here and you can view the the resulting mark via give's web interface