CIS15BG - CIS 15BG 1 Test 1 Questions: Chapters 8, 9, 10,...

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

View Full Document Right Arrow Icon
CIS 15BG Test 1 Questions: Chapters 8, 9, 10, 11 Computer Science is no more about computers than astronomy is about telescopes. - Edsgar W. Dijkstra Chapters: 8, 9, 10, and 11 ______________________________________________________________________ 1. Functions, loops, logical expressions, arithmetic expressions (A). If n = 12345 , what is the value returned from fun ? int fun( int n ) { int d; int r; r = 0; while( n != 0 ) { d = n % 10; r = r * 10 + d; n = n / 10; } return r; } (B) If size, the length of an array, is 7 and the array is declared as: int ary[10] = {5, 3, 7, 6, 15, 8, 10}; What is the value returned from the function guess ? What does the function guess do? int guess( int ary[], int size ) { int j; int k; j = ary[size – 1]; for( k = size – 2; k >= 0; k-- ) if( j > ary[k] ) j = ary[k]; return j; } 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
CIS 15BG Test 1 Questions: Chapters 8, 9, 10, 11 2. (A). One Dimensional Arrays – Sorting: Both selection and bubble sorts exchange elements. The insertion sort does not. Explain how the insertion sort rearranges the data without exchanges. (B) One Dimensional Arrays – Searching: Given the following fragment of code, circle the errors and correct them (Hint: there are 5 errors) // Prototype Declarations int binSearch( float ary[], int size, float target, int* locn); // Local Definitions float list[100] = {5, 5, 8, 9, 10, 10, 25, 90, 50, 60}; int size = 10; float target = 25; int* locn; int found; // Statements // a calling statement for binary search found = binSearch( ary[], size, target, locn); 2
Background image of page 2
Image of page 3
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 Winter '10 term at DeAnza College.

Page1 / 8

CIS15BG - CIS 15BG 1 Test 1 Questions: Chapters 8, 9, 10,...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online