Here is the question: Assuming int numbers[SIZE];is initialized somehow, write a function counter() that you an send the array to, plus an extra integer, and the function will return the number of times that value is found in the array. For example, if the array of SIZE 7 contains {1,2,3,2,3,3,3} then the call
x=counter(numbers,SIZE,3);will put 4 into x.
My try-
int integer;
int count=0;
cin >> integer;
int counter(numbers,SIZE, integer)
for(int i=0; i while(i if numbers[i] = integer
count++;
while(i=SIZE)
cout << count;
okay i think this ^^ is CLOSE to the right idea but i know its still wrong. help?

Respuesta :

Limosa

Answer:

Following are the code in C++ language.

int integer,c=0  ;// variable declaration

int counter(int numbers[], size, integer)  // function definition

{

for(int k=0; k<size; k++)   // iterating over the loop

{

if (numbers[k] = integer)  // check the condition value is found in the array

{

c++;  // increment of count variable

}

return (c); // returns count

}

Explanation:

Following are the description of the code.

  • Declared a "integer" which is "int" type that indicating the value to be searched.
  • Define a function "counter" which has 3 value in their  function header array "numbers[]" , size of the array and the value which is to be searched.
  • Iterating over the loop inside that for loop check the condition value is found in the array .
  • If value is found in the array then it returns the number of counts.