c17su02t1 - CSc 17 Test 1 6 June 2002 >SUGGESTED ANSWERS<...

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

View Full Document Right Arrow Icon
CSc 17 Test 1 6 June 2002 >>>>>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<< 1. (20 pts) Given some function "statement()" and the code for(int j=0;j<n;j+=3) statement(j); a) Write a while loop which has the same effect as the above for loop b) Write a do-while loop which has the same effect as the above for loop --------------------------------------------------------- int j; j=0; while(j<n) {statement(j); j+=3; } int j; j=0; if(j<n) do {statement(j); j+=3; }while(j<n); 2. (20 pts) Given the code int j,k; cin>>j>>k; if(j>k || k>2) if(j<k & k if((j==k)==(k==4)) cout<< 3; switch(j+k) {case 1: case 2: cout<<4; case 3: break; case 4: cout<<5; default: cout<< 6; } State the output if the user enters (in the given order on the line) a) 1 3 b) 4 2 c) 0 1 d) 8 -6 e) 1 2 -------------------------------------------------------------- 156 26 34 24 3 3. (20 pts) Given the functions void out(int x[]) {cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<endl;} {a=b+c; b+=c; c+=b; } State the output when the following code is executed:
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2008 for the course CSE 17 taught by Professor Varies during the Spring '08 term at Lehigh University .

Page1 / 2

c17su02t1 - CSc 17 Test 1 6 June 2002 >SUGGESTED ANSWERS<...

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

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