title: Recursive sum of an array in C
body: <p>Hello I'm learning recursion in C and I am trying to find the sum of the elements.</p>
  
  <p>This is my main:</p>
  
  <pre><code>int main()
  {
  
  
      int arr[] = {1,2,3,4,5};
      int sum;
      sum = arr_sum(arr,4);
      printf("\nsum is:%d",sum);
  
  
  
      return 0;
  
  }
  </code></pre>
  
  <p>And my recursive function:</p>
  
  <pre><code>//n is the last index of the array
  
  int arr_sum( int arr[], int n )
  { // must be recursive
  
      int sum = 0;
      //base case:
      if (n &lt; 0) {
          return sum;
      } else{
          sum = sum + arr[n];
      }
      //make problem smaller
      arr_sum(arr,n-1);
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>sum is :0 
  </code></pre>