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< iostream>
int main()
{
int a[100],n,count=0,num,i;
cout<<"Number of elements in array ?"<< endl;
cin>>n;
//input in array
cout<<"Enter "<< n<<" number in array"<< endl;
for(i=0;i< n;i++)
cin>>a[i];
cout<<"Enter number to search"<< endl;
cin>>num;
//Find occurrence
for(i=0;i< n;i++)
{
if(num==a[i])
count++;
}
cout<<"Occurrence of "<< num<<" in array is "<< count;
}
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