CISC105 Fall 2006 Lab10 CISC105 Fall 2006 Lab10

Programs

  1. Write a void function f that has no parameters. Inside the function, declare
    int i = 0;
    
    
    and then print both i and the address of i (do you remember the correct format specifier?). After you print i, but before the return, increment i. In main(), call your f 3 times and observe the result.
    Now in the same program, copy the function f, change the function name to g, and modify the declaration of i by placing the word "static" and a single space before the type.
    In main(), add three calls to g and observe the result. Think about: What happens to the "= 0"? Why doesn't it happen again? Answer in your comments: how does the word "static" modify where i is declared? Does the i in f appear to be close to the i in g in memory? According to our description of how functions work, what part of memory is f's i in?

  2. Re-write the recursive selection sort program from class for practice. If you get stuck, look at the online version, but try to do it yourself. Feel free to change names to ones that make sense to you.
    Then declare an integer array of size 1000, fill it with random numbers, and sort them. Print the first ten and last ten unmbers from the array before and after sorting.

  3. Copy the previous program, and modify it so that it can sort an array of "strings". How can you compare strings to see which comes first? How will you swap two strings?
    You'll need a 2d array of char, 20 rows by 10 columns; fill it with words you choose (unsorted) and sort it. Print the strings before and after sorting.

You should have a total of 3 programs named lab10.1.c to lab10.3.c. Make a single script file (see lab00 for the instructions) where you cat, compile, and run each one in its final form.

Submit all C files and your script on WebCT, and give the paper version of the complete script file only to your TA at the beginning of your next lab (all Friday labs) or in lecture Friday (Wednesday labs only). Note: Cat, compile, and run each program in order! Do not cat all programs, then compile, etc.



File translated from TEX by TTH, version 3.38.
On 9 Nov 2006, 23:39.