| CMPSC 101 - array worksheet #2 | Name - |
1. Write a code segment that uses a for loop to add the integers stored in the array named scores. You can assume that scores was already declared to be an array of int's with a size of 15.
2. Assume that scores is an array of double's with a size of 100. Write a code segment that uses a for loop to display the elements that are greater than 20.
3. Assume that scores is an array of int's with a size of 50. Write a code segment that uses a for loop to display any integers stored in the array which are odd.
4. Assume that oddsAndEvens is an array of integers with a size of 40. Write a code segment that uses a for loop to display the sum of the odd numbers and the sum of the even numbers that are stored in the array.
5. Assume that numbers is an array of integers with a size of 60. Write a code segment that replaces every negative element with its positive value (e.g. replace -3 with 3) until the value 0 is found in the array.
6. Assume that scores is an array of integers of size 10 and that idNumbers is another array of integers. Write a code segment that allows the user to input an integer score. The code segment should use a loop to find the score in scores and then display the corresponding integer that is stored in the same position of the parallel array idNumbers. If the integer score is not found in scores, the code segment should display "ID number not found".