CSCI 240 - Quiz Question - Week 10
0. (2) Declare an array to hold 4 integers. Fill it with the numbers 2, 4, 6, and 8.
1. (3) Assume an array called AR contains 4 integers. Write a loop to print out the values of the 4 integers.
2. (4) Assume an array called AR contains 4 integers. Write code to exchange the very first and the very last values in the array.
3. (2) Declare an array to hold 1000 integers. In the declaration statement, initialize the array so the very first value is 10, the second is 20, and all the rest are 0.
4. (2) Complete the following sentence: If you declare an array to hold N values, legal subscripts run from _____ to ______.
5. (2) Complete the following sentence: the unsubscripted name of an array is _______________________________.
6. (4) Write code to swap element [2] and element [4] in an array of floats called ar. Declare a simple variable called temp for this question, and assume the array is correctly declared and initialized.
7. (2) Write code to copy the 0th element of an array called ar into all the other elements of the array. Assume there are 10 elements.
8. (2) Complete the following sentence: all the elements of an array must be the same ____________.
9. (2) (T/F) You must initialize all the declared elements in an array in your program.
10. (4) Write a function to square the first N elements in an array of doubles.
11. (4) Write a function to return the average of the first N elements in an array of doubles. The function can assume N >= 0.