Skip to main content

Section 22.4 Practice: Bisection Search

Check Your Understanding Check Your Understanding

1.

Which of the following is the correct sequence of instructions to swap the values of two variables a and b (you may use an additional variable c if you wish)?
Feel free to use the window below to try out some code. Be sure to work the correct answer out "by hand" first before verifying your answer using the code window.

Compile and run the code below in your own C environment.

#include <stdio.h>

int main(void) {
   
   int a, b, c;
   
   /* Give it a try! Assign values to a and b and attempt to swap them.
      Be sure to print the values before and after the swap to be sure
      it worked properly. */
      
   return(0);
}
  • c=a; a=b; b=c;
    
  • Correct
  • c=b; a=c; b=a;
    
  • Not quite. Try again!
  • a=b; b=c; c=a;
    
  • Not quite. Try again!
  • a=b; b=a;
    
  • Not quite. Try again!