In: Computer Science
Function named FunCount takes three arguments-
C, an integer representing the count of elements in input list
IP- input list of positive integers.
Item- an integer value.
Function FunCount returns an integer representing the
count of all the elements of List that are equal to
the given integer value Key.
Example: Don’t take these values in program, take all inputs from user
C = 9, IP= [1,1,4,2,2,3,4,1,2], Item = 2
function will return 3
IN C PROGRAMMING
CODE:
#include <stdio.h>
int FunCount(int C,int IP[],int Item){
int count=0;
// iterate the array and check of the item equals the array elements
for(int i=0;i<C;i++){
if(IP[i]==Item)
count++;
}
return count;
}
int main(void) {
int len,item;
// take user input
// array size
printf("Enter the length of array: ");
scanf("%d",&len);
int arr[len];
//whole array
printf("Enter the items of the array: ");
for(int i=0;i<len;i++){
scanf("%d",&arr[i]);
}
// search item
printf("Enter the search item: ");
scanf("%d",&item);
// call the function and print the result
printf("Count: %d\n",FunCount(len,arr,item));
return 0;
}
OUTPUT:
Please
upvote if you like my answer and comment below if you have
any queries or need any further explanation.