unc comp 110 fall 07.   

Arrays and loops recitation


Purpose:

The main purpose is to learn about for loops and arrays. Arrays store lists of data and for loops are used to traverse them. We start by reviewing for loops from last week. Last week we only got as far as the while loops.

We review two kinds of arrays. The first is a regular array defined with square brackets []. The second kind of array is a string variable. A string is an array of characters.

Again, these exercises are based on explanations in the lecture slides. Refer to the slides for details.

Parts

Answers
  1. Part 1
    1. See last week
  2. Part 2
    1. Display array
    2. Compute average
  3. Part 3
    1. Display string
    2. Count A
    3. Count B