
CGS 3460 - Programming Using C
Summer 2009
Assignment #5
20 Points
Assigned: 06/12/2009, Friday
Due: 06/19/2009, Thu, 11:59 PM
1. (5 Points) Write a program that reads in 11 integers from the user and puts them
into an array in the order entered by the user. The program will then send this
array to a FUNCTION which calculates and prints the mean and median. The mean
is the sum of the numbers divided by 11. The median is the midpoint value (half of
the numbers are above it, and half are below it). To calculate the median, the
array must be sorted. You may want to consider the quicksort function defined in
chapter 9 of the course textbook.
Save this as p1.c
2. (5 Points) Write a program that reads an integer, N, from the user. The program
then calls a function with the following function declaration N times.:
void functionForProb2( );
This function will print the message “I've been called %d times\n”, where %d is the
actual number of times the function has been called. The function can only use
variables declared within the function. i.e. no global (external) variables and no
parameters are sent to the function.
Save this as p2.c
3. (5 Points) Write a program which defines the following function.
void get_rational(int *num, int *den)
This function should read a rational number from the user. The rational number
should be entered in the form “i/j” where i and j are integers. It should return the
numerator(i) in num and the denominator in den. The main function will then print
out both the numerator and the denominator.
Save this as p3.c
4. (5 Points) This part is not a programming assignment that will be compiled. I am
asking you to trace the code manually. You could code, compile and run these
programs to get the answer, but as you will not have a computer available to you
on the exam, I would not suggest this. Put the answers to these in a text file called
p4.txt.
a) What will be the output to the following program.
void swap(int a, int b);