How To Calculate Frequency In An array

Assume the array has [0 0 1 1 1 0 0 0 0 1 1 0 1 1 1]

I would like to store 1's that has been repeated. As the example above, I would like to store 111 into an array and 11 into another.

My expected output should be

arr[3]=2 //means continuous of 1 has been 3 times and been encountered 2 times
arr[2]=1 //continuous of 1 is 2 times in length and been encountered once

1
2
3
4
5
6
  for(x=0;x<15;x++){
  getval=arr[x]
  if(getval==0)
  arr1[x]=arr[x];
  else if(getval==1)
  arr2[x]=arr[x];
Why u dont try something like this?:


arr[15]= [0 0 1 1 1 0 0 0 0 1 1 0 1 1 1];

int counter=0;

for(x=0;x<15;x++){
getval=arr[x]

if(getval==0) arr2[x]=counter;

else if(getval==1){
counter++;
arr2[x]=counter;)
)



Topic archived. No new replies allowed.