0

Hi, I am trying to create a c++ program for counting the number of occurrences in an array using 2 1-D arrays such that the first array contains the elements and the second array gives the count of the number of occurrences of each element in the first array. Unfortunately, whenever i try to find this program, it only involves just one array and the count just prints number of elements frequently occurring in a for loop. Could somebody please provide me the code? I would really appreciate the assistance.

3
Contributors
3
Replies
27
Views
4 Years
Discussion Span
Last Post by emcela
-1

Try this (you do the definitions and declarations), I just thought this might work, didn't test it.

k=1;
    for(i=1;i<=n;i++)
        {kk=1;
         for(j=1;j<=n;j++)
            if(x[i]==x[j]) k++;
            y[kk]=k;}


     for(j=1;j<=n;j++)
        if(x[i]==x[j]) k++;
        y[kk]=k;}
0

Sorry, no lines 9,10,11.

k=1;
    for(i=1;i<=n;i++)
        {kk=1;
         for(j=1;j<=n;j++)
            if(x[i]==x[j]) k++;
            y[kk]=k;}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.