Occurrence of the number in array by R4R Team

Array:
Collection of different values having same data type is known as Array.

Example-
Array is 1 2 5 9 1 8 9 1
Occurrence of 1 is 3
Occurrence of 2 is 1
Occurrence of 9 is 2

program-

#include< stdio.h>
int main()
{
int a[100],n,count=0,num,i;
printf("Number of elements in array ?\n");
scanf("%d",&n);
//input in array
printf("Enter %d number in array\n",n);
for(i=0;i< n;i++)
scanf("%d",&a[i]);
printf("Enter number to search\n");
scanf("%d",&num);
//Find occurance
for(i=0;i< n;i++)
{
if(num==a[i])
count++;
}
printf("Occurrence of %d in array is %d",num,count);
}


output-

Number of elements in array ?
6
Enter 6 number in array
1 3 2 1 2 3
Enter number to search
1
occurrence of 1 in array is 2

Number of elements in array ?
6
Enter 6 number in array
1 3 2 1 2 3
Enter number to search
8
occurrence of 8 in array is 0

-In this program, we take a input in the array of size n.
-We run loop n times for the array and search whole array for particular number and count




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!