Answer:
Following are the function of count:
void count(int y,int x[],int n) // function definition of count
{
int k,count=0; // variable declaration
for(k=0;k<n;++k) // iterating over the loop
{
if(x[k]==y) //check the conndition number of times the value of y occurs
{
count++; // increment of count by 1
}
}
Explanation:
Following are the code in c language
#include <stdio.h> // header file
void count(int y,int x[],int n) // function definition of count
{
int k,count=0; // variable declaration
for(k=0;k<n;++k) // iterating over the loop
{
if(x[k]==y) //check the conndition number of times the value of y occurs
{
count++; // increment of count by 1
}
}
printf(" the number of times the value of y occurs :%d",count); // display count value
}
int main() // main method
{
int x[100],y,n,k; // variable declarartion
printf(" Enter the number of terms n :");
scanf("%d",&n); // input the terms
printf(" Enter the array x :");
for(k=0;k<n;++k) // input array x
{
scanf("%d",&x[k]);
}
printf("Enter the value of y:");
scanf("%d",&y);// input value y by user
count(y,x,n); // calling function
return 0;
}
In the given program we declared an array x ,variable y and n respectively Input the array x ,y,n by user after that we call the function count .In the count function we iterate the loop from o position to array length-1 and check the number of times the value of y occurs by using if statement i.e if(x[k]==y) if the condition of if block is true then we increment the count variable Otherwise not .Finally display the count variable which describe the number of count.
Output
Enter the number of terms n :5
1
2
2
56
5
Enter the value of y:2
the number of times the value of y occurs :2
Enter the number of terms n :5
1
2
3
56
5
Enter the value of y:26
the number of times the value of y occurs :0