CS 1401, Quiz 10

Date: Monday, November 5, 2007
Name (please type legibly, ideally in block letters): ______________________________________________________________________
Class section (9:30 am or 11:30 am): _______________________________

1. Write a piece of code that, given an array ar of integers, computes the sum of all positive elements of this array.

2. To check the correctness of the code you wrote in Problem 1, write a piece of code that defines a new array ar consisting of 2 elements of type integer and assigns, to elements of this array, values 5 and -3. Trace step-by-step how the piece of code you wrote in Problem 1 will compute the sum of all positive elements of this array (the answer should be 5).