summaryrefslogtreecommitdiff
path: root/data/test14.c
blob: 45565fab94fd038d6822d4a8e41e6b64ade279ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Sum the first n elements of the array
int sum(int x[], int n) {
  int i;
  int sum;
  i = 0;
  sum = 0;
  while (i < n) {
    sum = sum + x[i];
    i = i + 1;
  }
  return sum;
}

void main() {
  int a[10];
  int i;

  println("This should print 6 and 28");
  i = 0;
  while (i < 10) {
    a[i] = i;
    i = i + 1;
  }

  println(sum(a, 4));
  println(sum(a, 8));
}