Unformatted text preview: le, Do while Loops (20 pts) Compete the following function that counts the number of positive (greater than zero) integers in an array, using three types of loops. See the comments for more details. The three versions should behave exactly the same. // Count the number of positive integers in an array
// X: the input array.
// N: the number of elements in the array, N > 0
// return: the counted number.
int count_positive(int X, int N)
a. [10 pts] Complete the function using a for loop. int count = 0;
for (int i = 0; i < N; i++) {
if (X[i] > 0)
count++;
}
return count; b. [5 pts] Complete the function using a while loop. int count = 0;
int i = 0;
while (i < N) {
if (X[i] > 0)
count++;
i++;
}
return count;
c. [5 pts] Complete the function using a do while loop. int count = 0; Name: Lab Section: int i = 0;
if (i < N) {
do {
if (X[i] > 0)
count++;
i++;
} while (i < N);
} Question 4: String Operations, Pointers, and C Library Functions (20 pts) You may only use pointers, not array, in the following exercises. a. [5] Complete the following function that returns the length of string s. int strlen(char *s)
{
int len =...
View
Full Document
 Fall '08
 Staff
 Array, Return statement, Natural number, Void type

Click to edit the document details