Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a function that counts the number of times the value of y occurs in the fi

ID: 3868794 • Letter: W

Question

write a function that counts the number of times the value of y occurs in the first n values in array x. y is an integer variable, x is an array of integers, and n is an integer variable. the name of the function must be count. the parameters must appear in the order of y, x, n. write a function that counts the number of times the value of y occurs in the first n values in array x. y is an integer variable, x is an array of integers, and n is an integer variable. the name of the function must be count. the parameters must appear in the order of y, x, n. write a function that counts the number of times the value of y occurs in the first n values in array x. y is an integer variable, x is an array of integers, and n is an integer variable. the name of the function must be count. the parameters must appear in the order of y, x, n.

Explanation / Answer

FUNCTION

//Function Implementation

int count(int y,int n,int x[])

{

int cnt=0;

for(int i=0;i<n;i++)

{

if(y==x[i])

{

cnt++;

}

}

return cnt;

}

______________

Complete Program:

#include <iostream>

using namespace std;

//Function Declaration

int count(int y,int n,int x[]);

int main()

{

int y=5;

int n=8;

int x[]={3,4,5,6,7,5,4,5,4,5,6,7,8,9,4};

int notimesOccur=count(y,n,x);

cout<<"No of Times occured :"<<notimesOccur<<endl;

  

return 0;

}

//Function Implementation

int count(int y,int n,int x[])

{

int cnt=0;

for(int i=0;i<n;i++)

{

if(y==x[i])

{

cnt++;

}

}

return cnt;

}

__________________Thank You