Answer to Question 14A-1

// numOdds(A,n) returns the number of odd values in
// A[0,...,n-1].

int numOdds(int A[], int n)
{
  int odds = 0;
  for(int i = 0; i < n; i++)
  {
    if(A[i] % 2 == 1)
    {
      odds++;
    }
  }
  return odds;
}

The following is a boilerplate way to do a scan algorithm on an array A of size n is.

  initialize result variable(s)
  for(int i = 0; i < n; i++)
  {
    update result variable(s) using A[i]
  }