/* File: sum2.c
   A simple recursive function to compute the
   sum of the elements of an array.
*/

#include <stdio.h>

int sum (int A[], int low, int high) {
   
   if (low == high) return A[low] ;

   return A[low] + sum(A, low+1, high) ;
}

main(){
  int A[5] = {1, 4, 9, 3, 2} ;
  int s ;

  s = sum(A, 0, 4) ;
  printf("sum A[0..4] = %2d\n", s) ;

  s = sum(A, 0, 0) ;
  printf("sum A[0..0] = %2d\n", s) ;

  s = sum(A, 0, 1) ;
  printf("sum A[0..1] = %2d\n", s) ;
}
