hi all this is an algo of finding the no. of times the key occurs in an array..
#include<iostream>
using namespace std;
int main()
{
int a[5]={1,2,2,5,6};
int max=2;
int counter=0;
for(int i=0;i<5;i++)
{
if(max==a[i])
counter++;
}
cout<<"the element "<<max<<" appears "<<counter <<" no. of times";
return 0;
}
on this pattern i want to find an element which occurs the largest no. of times in da array??
i m stuck in it..dont know how to do
i m sending my code..
#include<iostream>
using namespace std;
int main()
{
int array[5]={1,2,2,5,6};
int counter=0;
int max;
for(int j=0;j<5;j++)
{
for(int i=0;i<5;i++)
{
if(array[j]==array[i])
{
max=array[j];
counter++;
break;
}
}
}
cout<<"the element which the largest no of time is : "<<max;
return 0;
}