title: Count Number of Digits in an array (c++)
body: <p>let's say I have an array
  arr[5]={5,2,3,2,5} and i wrote following program for it</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int main()
  {
    int n;
    cout&lt;&lt;"Enter Length of Elements= ";
    cin&gt;&gt;n;
    int arr[50];
    for(int i=0;i&lt;n;i++)
    {
        cout&lt;&lt;"Enter Number=";
        cin&gt;&gt;arr[i];
    }
    for(int i=0;i&lt;n;i++)
    {
        int countNum=1;
  
  
        for(int j=i+1;j&lt;n;j++)
        {
            if(arr[i]==arr[j])
            {
                if(i&gt;0)
                {
                    int countNum2=0;
  
  
                    for(int k=0;k&gt;i;k++)
                    {
                        //bool repeat=false;
  
                        if(arr[i]==arr[k])
                        {
                          //repeat=false;
                        }
                        else
                        {
                            countNum2++;
                        }
                    }
                    if(countNum2==i)
                    {
                       countNum++;
                    }
                }
                else
                {
                  countNum++;
                }
            }
            else
            {
                for(int k=0;k&lt;i;k++)
                {
                    if(arr[k]==arr[i])
                    {
  
                    }
                    else
                    {
                        countNum=1;
                    }
  
                }
            }
  
        }
        cout&lt;&lt;arr[i]&lt;&lt;" has appeared "&lt;&lt;countNum&lt;&lt; "Times"&lt;&lt;endl;
  
    }
  
      return 0;
  }
  </code></pre>
  
  <p>but why I am getting
  5 has appeared 2 Times</p>
  
  <p>2 has appeared 1 Time</p>
  
  <p>3 has appeared 1 Time</p>
  
  <p>2 has appeared 1 Time</p>
  
  <p>5 has appeared 1 Time</p>
  
  <p>instead of </p>
  
  <p>5 has appeared 2 Times</p>
  
  <p>2 has appeared 2 Times</p>
  
  <p>3 has appeared 1 Times</p>
  
  <p>so how to fix my program 
  help!</p>