2_Questions_8-1

# 2_Questions_8-1 - CIS 15AG Questions Chapter 8: Arrays 1 1....

This preview shows pages 1–3. Sign up to view the full content.

CIS 15AG Questions Chapter 8: Arrays 1. Fill in the blanks. Assume list is containing: 15, 90, 50, 60, 20, 55, 15, 25, 45, 35 and size stores the actual number of elements in the list, in this case 10. // Code a printf statement to print the first element in the list. printf( "%5d\n", list[0] ); // ...the third element in the list: 50 printf( "%5d\n", ); // ... the last element in the list: 35 printf( "%5d\n", ); // ... the seventh element in the list : 15 printf( "%5d\n", ); 2. Fill in the blanks. Assume list is containing: 15, 90, 50, 60, 20, 55, 15, 25, 45, 35 and size stores the actual number of elements in the list, in this case 10. // Change the second element in the list: add 10 to it, then print it. printf( "%5d\n", ); // Find the average of the first and last element in the list. avg = printf( " average: %.2f\n", avg ); 3. Fill in the blanks. Assume list is containing: 15, 90, 50, 60, 20 and it is defined with a maximum size of 100: int list[100]; also size stores the actual number of elements in the list, in this case 5; // Write code to add num , a number entered by the user, at the end of the list printf( "Enter num: " ); scanf ( "%d", &num ); 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Questions Chapter 8: Arrays 4. Indicate if the following are valid references to the array a, and if valid, specify the value of the element referenced (show how you arrived at the answer) int a[10] = { 1, 4, 6, 8, 9, 3, 7, 10, 2, 8 }; a[4] a[0] a[a[0] + a[4]] a[2 + 6.0 / 3] a[1 + 11 % 2] 5. Which statement best describes the following program segment, assuming the declarations shown below? int list[1000]; int i; for ( i = 1; i <= 500; i++ ) printf( "%3d", list[ 2*i - 1 ] ); a. The segment displays all odd elements. b. The segment contains a subscript error. c. The segment displays all the elements in the first half of the array. d. The segment displays all elements with an odd subscript. e. The segment displays all elements in the first half of the array with an odd subscript. 2
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/02/2011 for the course CIS 15BG taught by Professor Staff during the Spring '10 term at DeAnza College.

### Page1 / 15

2_Questions_8-1 - CIS 15AG Questions Chapter 8: Arrays 1 1....

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online