title: Sum the positive elements of an array using recursion
body: <p>I'm learning recursion and trying to calculate the sum of the positive elements of an array but I don't know how to do it. Can anyone help me?</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  using namespace std;
      
  int sum (int arr[],int n)
  {
      if(n==-1)
      return  0;
      /*else if(arr[n]&lt;0)
      return arr[n]+sum(arr,n+1) ;*/
      else
      return arr[n-1]+sum(arr , n-1);
          
  }
      
  int main()
  {
      int  n , arr[n] ;
      cout&lt;&lt;&quot;give the value of  n : &quot; ; cin&gt;&gt;n;
      cout&lt;&lt;&quot;give the values of the array &quot;;
      for(int i=0;i&lt;n;i++)
      cin&gt;&gt;arr[i];
      cout&lt;&lt;&quot;the value of positive elements is  : &quot; &lt;&lt; sum(arr,n);
      return 0;
  }
  </code></pre>