{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# CS1050302a - Computer Science Foundation Exam May 3 2002...

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

Computer Science Foundation Exam May 3, 2002 COMPUTER SCIENCE I Section I A No Calculators! KEY Name: SSN: In this section of the exam, there are four (4) problems You must do all of them. The weight of each problem in this section is indicated with the problem. The algorithms in this exam are written in C programming language notation. Partial credit cannot be given unless all work is shown. As always, be complete, yet concise, and above all be neat . Credit cannot be given when your results are unreadable. 1

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

View Full Document
(1, 16%) (C code) Given the following array and program segment, answer the questions below. Array x 5 2 6 1 3 7 position 012345 int x[6] = {5,2,6,1,3,7}; int i, j, k, a, b, t; i=0; j=5; a=0; b=0; while (i<j){ if (x[i]<x[j]) { k=i+1; while (k<j) { if (x[k]<x[k+1]) { a=a+1; t=x[k]; x[k]=x[k+1]; x[k+1]=t; } k=k+1; } // end of inner while loop x[i]=x[i]+a; i=i+1; } else { k=j-1; while (k>i) { if (x[k]>x[k-1]) { b=b+1; t=x[k-1]; x[k-1]=x[k]; x[k]=t; } k=k-1; } // end of inner while loop x[j]=x[j]+b; j=j-1; } } // end of outer while loop a) Show the array x after the program segment is executed (2 pts. each).
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

CS1050302a - Computer Science Foundation Exam May 3 2002...

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

View Full Document
Ask a homework question - tutors are online