{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw3-solutions

# Int count 0 name lab section int i 0 if i

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern