/* Demonstrates how arrays behave when passed as arguments
   Created:  Joe Zachary, Novemver 3, 1992
   Modified:
*/

#include <stdio.h>

/* This function takes an array and its size as an argument
   and returns the sum of its elements. */

int addArray (int A[], int n) {
  int i;
  int sum = 0;
  for (i=0; i<n; i++)
    sum = sum + A[i];
  return(sum);
}


void main (void) {

  int y[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

  printf("The sum of the first 10 elements is %d\n", addArray(y, 10));

  printf("The sum of the first 5 elements is %d\n", addArray(y, 5));

  printf("The sum of the first 20 elements is %d\n", addArray(y, 20));

}

