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
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
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
This is the end of the preview.
Sign up
to
access the rest of the document.
 Winter '10
 Staff
 Computer Science, Computer Programming, Array, fb, printf, dimensional arrays, Edsgar W. Dijkstra

Click to edit the document details