title: Program to find number of elements between two elements a and b (where a and b both are inclusive)
body: <blockquote>
  <p>Given an unsorted array of size n, write a program to find number of elements between two user-defined elements a and b (where a and b both are inclusive) of a user-defined array.<br />
  Input : arr = [1, 2, 2, 7, 5, 4]<br />
  a=2 b=5<br />
  Output : 4<br />
  (The numbers are: 2, 2, 5, 4).<br />
  If a=6 b=15, then output will be 3 (The numbers are: 6, 7, 15)</p>
  </blockquote>
  <p>I tried the following code, but for arr = [1, 3, 3, 9, 10, 4] and for a=9 &amp; b=12, it is showing the output:- 2. But the output should be 3. I can't figure out the proper logic to solve the question.</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      int n,i,a,b,c=0,d=2;
  
      printf(&quot;Enter size of array: &quot;);
      scanf(&quot;%d&quot;,&amp;n);
      
      printf(&quot;Enter elements of array: &quot;);
  
      int arr[n];
      
      for(i=0;i&lt;n;i++){
          scanf(&quot;%d&quot;,&amp;arr[i]);
      }
   
      printf(&quot;\nEnter lower limit element &amp; upper limit element respectively: &quot;);
      scanf(&quot;%d %d&quot;,&amp;a,&amp;b);
  
      for(i=0;i&lt;n;i++){ 
          if(arr[i]==a || arr[i]==b){
              c++;
              d=0;
          }
          
          if(arr[i]&gt;a &amp;&amp; arr[i]&lt;b){
              c++;
          }
      }
  
      printf(&quot;Number of elements in between two elements (Both Inclusive) = %d&quot;,c+d);
  
      return 0;
  }
  </code></pre>
  <p>Please suggest the logic. I will be very thankful for that.</p>