Program to print number of occurrences of each number in the array

arroccr

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
// Coded by : Shahbaz Hashmi
int t,c,p;
int ar[20] = {3,2,1,4,5,6,2,3,5,9,8,6,1,0,7,2,1};
int n = 17; // number of elements
for(int i=0;i<n;i++)
{
t=ar[i];
c=p=0;
for(int j=0;j<n;j++)
{
if(t==ar[j])
{
c++; // for counting occurrence of each number
}
}

for(int k=i+1;k<n;k++)
{
if(t==ar[k])
{
p++; // increments when same number is present ahead in the array
}
}

if(p==0) // checks the number is present ahead or not
{
cout<<t<<” is found “<<c<<” times”<<endl;
}
}
getch();
}

You may also like...

1 Response

  1. Thanks meant for offering such superior data.

Leave a Reply

Your email address will not be published. Required fields are marked *