C Programming Homework #11: Pointers

Due: Monday, April 25, 2016

See Lesson #19, Lesson #20, and Lesson #21 in my C tutorial.

  1. Write a function that uses pointers to exchange every pair of elements in an array. If the array has an odd number of elements, leave the last element alone. For example if given the array:

      1 2 3 4 5
    

    your function should produce the array:

      2 1 4 3 5
    

    Notice how the (1, 2) have been exchanged and the (3, 4) have been exchanged. Here is a declaration of the function:

      void swap_pairs( int *array, int size );
    
  2. Write a main program that exercises your function so you can check if it is working properly. Put both your function and your main program in the same file.

Submit your source file to Moodle.


Last Revised: 2016-04-20
© Copyright 2016 by Peter C. Chapin <PChapin@vtc.vsc.edu>