Swap Function
Download
swapFunction.c
,
or copy it into your current directory on a CSE system by running
$ cp /web/cs1511/17s2/week05/files/swapFunction.c .
You have been given an incomplete main
function,
as well as a swap
function to implement.
First, complete the void swap(int *a, int *b)
function,
which takes in pointers to two integers, and must
swap their values around so that they are swapped
once the function is complete.
Then, on line 17, call the swap
function on the
two variables, a
and b
,
which have been read in. Do not change
any other part of the main
function.
Some Examples
Enter two numbers: 1 33 The numbers swapped are 33 and 1.
Enter two numbers: 17 -17 The numbers swapped are -17 and 17.
To run some simple automated tests:
$ 1511 autotest swapFunction
To run Styl-o-matic:
$ 1511 stylomatic swapFunction.c Looks good!
You’ll get advice if you need to make changes to your code.
Submit your work with the give command, like so:
$ give cs1511 wk05_swapFunction
Or, if you are working from home, upload the relevant file(s) to the wk05_swapFunction activity on Give Online.