to count how many time each element occur in an array.
Answers
Answered by
0
In general we count from 0 to no.... E.g.
int a[]=new int[10]. So i has 9 elements.
But easiest way is total -1 i mean to say In above e.g. there are how many element? 10 ohk ... now -1 it have 9 elements according to computer got that.
BEST OF Luck
int a[]=new int[10]. So i has 9 elements.
But easiest way is total -1 i mean to say In above e.g. there are how many element? 10 ohk ... now -1 it have 9 elements according to computer got that.
BEST OF Luck
Answered by
0
let may be you generated array already and declared elements of it..
then..
int count=1;
for(int i=0;i<n;I++)
{
for(j=0;j,N;J==00
{
If(a[i]==a[j])
{
count=count+1;
}
print "element"+a[i]+"repeated for"+count+"times";
count=1;
}
}
o/p:
let array e a[]={1,2,3,4,1,1,2,,3,3,3};
then 1 repeated for 3 times
2 repeated for 2times
3 repeated for 4 times...so on..:)
keep smiling...
then..
int count=1;
for(int i=0;i<n;I++)
{
for(j=0;j,N;J==00
{
If(a[i]==a[j])
{
count=count+1;
}
print "element"+a[i]+"repeated for"+count+"times";
count=1;
}
}
o/p:
let array e a[]={1,2,3,4,1,1,2,,3,3,3};
then 1 repeated for 3 times
2 repeated for 2times
3 repeated for 4 times...so on..:)
keep smiling...
Similar questions