google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a c program to find the frequency of presence an element in an array - 2nd puc computer science

Write a c program to find the frequency of presence an element in an array

c program frequency of array,count frequency of each element in an array,frequency array example,how to count occurrences of each element in an array in c,c program frequency of array

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


Write a c program to find the frequency of presence an element in an array Write a c program to find the frequency of presence an element in an array Reviewed by Vision Academy on December 17, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.