Answer to Quiz 12(a) Tue 20 Nov 2001

1 Consider

            float minimum ( int n, float a[] )
            /* returns the minimal element in the array */
            {
               float min = a[0];
               int i;

               for (i = 1; i < n; i++)
                  if (a[i] < min) min = a[i];

               return min;
            }

Give the equivalent definition of minimum
with pointers only, avoiding ALL brackets:

            float minimum ( int n, float *a )
            {
               float min = *a;
               float *p;

               for (p = a; p < a+n; p++)
                  if (*p < min) min = a[i];

               return min;
            }

2. Write the definition of a function that reverses the
   order of characters in an array.  For example, the reverse
   of {'d','r','a','w'} is {'w','a','r','d'}.

 void reverse ( int n, char word[n] )
 /* reverses the order of characters in a word of n letters long */
 {
    char c;
    int i;
 
    for (i = 0; i < n/2; i++)
    {
       c = s[i];
       s[i] = s[n-i-1];
       s[n-i-1] = c;
    }
 }
FINAL EXAM is in C6 on Monday 3 December 2001 from 1:00 till 3:00PM.