// copyPositives(A, B, n) copies the positive numbers // in B[0,...,n-1] into array A, preserving order. // // It returns the number of values stored into array A. // If the return value is k then the positive numbers // from array B are in A[0,...,k-1]. // // Requirement: array A must have enough room for // all of the positive numbers in B[0,...,n-1]. int copyPositives(int A[], const int B[], int n) { // i is the index in B. // k is the index in A. int i, k; k = 0; for(i = 0; i < n; i++) { if(B[i] > 0) { A[k] = B[i]; k++; } } return k; }