EXERCISES ON ARRAYS



 1. (a)  What happens if you declare an array with 
            #define N 1000
            int a[N];

    (b)  What happens if you declare an array with 
            #define N 1000
            int a[N*N];

    (c)  What happens if you declare an array with 
           #define N 1000
           int a[N*N*N];


 2. What is in a[8] after the following code is executed?

          for (i = 0; i < 10; i++)
             a[i] = 9 - i;
          for (i = 0; i < 10; i++)
             a[i] = a[a[i]];


 3. The following C program is supposed to read in a sequence of integers
    between 0 and 99 and return a value that occurs most frequently (mode).
    Identify 7 errors.

          void main(void) {
             int num, i, maxi, a[99];
             while (scanf("%2d", num) != EOF)
                a[num]++; 
             for (i = 0; i <= 99; i++);
                if (a[i] > a[maxi])
                   maxi = i;
             printf("mode = %d\n", maxi);
          }

The rest of the array exercises are in "Notes on Arrays."