WAP to find frequency of element in C
Here is your code in C -
#include <stdio.h>
int main()
{
int a[5], i, freq=0, key;
printf("Enter the elements of array: ");
for (i=0; i<5; i++) {
scanf("%d", &a[i]);
}
printf("Enter the element whose frequency you want to find: ");
scanf("%d", &key);
for (i=0; i<5; i++) {
if (key == a[i])
freq ++;
}
printf("\nFrequency of %d is %d", key, freq);
return 0;
}
Output -

Comments
Post a Comment