Version Three

Because we are now using an array with ten elements, instead of ten different variables, it is possible to dramatically shorten our program by using a for loop. Take a look at the third version of the program (``array3.c'' in your ``examples'' directory). What have we done to take advantage of the array?

Click here for the answer

How could you change this program so that it read and printed out 12 numbers instead of 10?

Click here for the answer

Does this convince you of the utility of arrays? If not, consider what changes would be required to the first version of our program if you wanted to read 100 numbers. Compare that to the changes that would be required in our latest version.


Eric N. Eide
Hamlet Project
Department of Computer Science
University of Utah