Write a c program to find the frequency of presence an element in an array
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i,ele,count=0;
clrscr();
printf("Enter the size of an array: ");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element whose frequency is to be
checked: ");
scanf("%d",&ele);
for(i=0;i<n;i++)
if(ele==a[i])
count++;
printf("%d has appeared %d times",ele,count,"
times");
getch();
}
Output
run 1:
Enter the size of an array: 5
Enter the elements
1
2
3
4
4
Enter the element whose frequency is to be checked: 4
4 has appeared 2 times
run 2:
Enter the size of an array: 5
Enter the elements
1
2
3
4
4
Enter the element whose frequency is to be checked: 5
5 has appeared 0 times
No comments: