title: How to find an element in array such that sum of left array is equal to sum of right array
body: <p>here is the input and output the code should generate:</p>
  
  <ul>
  <li>Input : <code>1 4 2 5 0</code></li>
  <li>Output : <code>2</code></li>
  </ul>
  
  <p>Explanation : If 2 is the partition, then: <code>1+ 4=5(LHS)</code> and <code>5+0=5(RHS)</code> should print <code>2</code>, but in my case I'm not getting the output.</p>
  
  <p>I tried my code with the logic that.. the n-th element would be present somewhere in between the array. So considering the sum of element of arr till n-th element will be LHS and from n-th element it would be till the end of the arr which is RHS. Also i added a while loop which increments the pointing element n. </p>
  
  <pre><code>#include &lt;iostream.h&gt;
  #include &lt;conio.h&gt;
  void main(){
     int arr[5],arr2[5],i,j=0,k=0,n=1;
     cout&lt;&lt;"input_arr\n";
     for(i=0;i&lt;5;i++)
      cin&gt;&gt;arr[i];
  
     while(n&lt;=5)
  {
     for(i=n;i&lt;5;n++)
        j+=arr[i];   //sum of right side arr from n-th   element
     for(i=0;i&lt;n;i++)
      k+=arr2[i];  //sum of left side arr till n-th element
     if(k==j)
      cout&lt;&lt;"\n"&lt;&lt;arr[n];  // prints the equilbrium element
     else
           n++;
  }
      getch();
  }
  </code></pre>