this is what I have. it is skipping over the zero. how can I fix that? I’m trying to count the number of times the numbers are duplicated.
void hit_rate(int a, int cmset[])
{
int i, j, k=0;
for(i=0;i<a;i++){
for(j=i;j<a;j++){
if((cmset[i] == cmset[j])){
k++;
}
}
printf("%d\n",k);
k=0;
}
}
cmset k **now** prints
4 2
6 1
0 3
0 2
0 1
1 1
2 1
4 1
While counting duplicates,
e.g.
arr[5] = {1, 2, 2, 3, 3};start with
comapre
arr[i] == arr[j]; //conditionBy this what happens if you have tested arr[0] with all i = 1..4;
in next iteration, you have need not to check a[1] with arr[0], because it’s already done (or checked).
increase the counter(when duplication matches). once it ends the end of the array reset counter. and print it.
I hope it helps. Still confused then I will provide you sample code.