// // Program: count_in_array // // Purpose: test recursive function for counting occurrences // of an element in an array. // // Input: // N integers for the array (currently N = 6), then an // integer X to look up in the array. // Output: // how many times X occurs in the array. // #include #include // has EXIT_SUCCESS // Recursive function to count occurrences of element in array. // Pre: n >= 0, and array a has at least n elements. // Post: returns how many elements of a[0] .. a[n-1] are // equal to x. // ADD YOUR FUNCTION HERE. // The prototype should be of the form // ?? count_in_array(?? x, ?? n, ?? a); // (Replace "??" with appropriate types.) // Main program. int main(void) { const int N = 6; int nums[N]; int x; cout << "Enter " << N << " numbers for array:\n"; for (int i = 0; i < N; i++) cin >> nums[i]; cout << "Enter number to search for:\n"; cin >> x; cout << x << " occurs " << count_in_array(x, N, nums) << " times in the array\n"; return EXIT_SUCCESS; }