APSC 2007 final solution 1

APSC 2007 final solution 1 - APSC 160 April 2007 Final Exam...

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

View Full Document Right Arrow Icon
APSC 160 April 2007 Final Exam Sample Solutions Question 1 A) a B) c C) c D) a E) a F) c G) d Question 2 (Take your pick of one of the following styles and answers. And, of course, other solutions are possible. Note that %d is equivalent to %i in the format specifier.) while (1) { if (arr[i] == k) { printf(“Found %i at location %i in array\n”, k, i); break; } else { /* these braces are optional */ i++; } } OR: int stop=FALSE; while (!stop) { if (arr[i] == k) { printf(“Found %d at location %d in array\n”,k,i); stop = TRUE; } else { i++; } } OR:
Background image of page 1

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

View Full DocumentRight Arrow Icon
int stop=FALSE; while (!stop) { if(arr[i]==k) { printf(“Found %d at location %d in array\n”,k,i); stop = TRUE; } else { i++; } } OR: while (arr[i]!= k) { /* these braces are optional */ i++; } printf(“Found %d at location %d in array\n”,k,i); OR even the short-cut: while(arr[i++]!=k); /* note that the body of the loop is empty */ printf(“Found %d at location %d in array\n”,k,i); Question 3 Trace table: main: x main: y bar: x bar: y bar: i Output to screen -1 12 1 0 8 1 -1 -1 0 0 12 9 0 1 9 bar: x=1 bar: x=-1 (x,y)=(12,0)
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 02/03/2010 for the course APSC APSC 160 taught by Professor Jeremyhiliker during the Fall '08 term at UBC.

Page1 / 4

APSC 2007 final solution 1 - APSC 160 April 2007 Final Exam...

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