/* q23a.c

 AN INCORRECT answer to Question 23, CISC105 Exam, Fall 2004 
 P. Conrad.  Compare this with q23.c in the same directory.

*/

#include <stdio.h>

#define SIZE 10

void findMin(int a[], int *min);

int main(void)
{

  int array[]; /* this is an illegal array declaration; need a size,
		  unless the array is a formal parameter, in which case
	          the array name is treated as a pointer.  */

  const int size = 10;
  int a[size];    /* this is ok */
  int nums[SIZE]; /* so is this */


  int min; /* minimum element in array */

  /*  prompt user for ten integers */

  printf("Please enter ten integers: ");

  /* The following is an incorrect way to read */
  /* 10 integers. You need a loop*/

  scanf("%d", a[10]);

  /* Likewise, the following is an incorrect way 
     to print 10 integers.  You need a loop*/

  printf("array is: %d\n",a[10]);

  /* The following is a incorrect function call */

  void findMin(a[], *min);

  /* The correct call would be: */

  findMin(a, &min);

  printf("min is: %d\n",min);

  return 0;
}

/* the following function definition is ok, I think */

void findMin(int a[], int *min)
{
  /* print the minimum value in the array */
  int i;

  *min = a[0];
  for (i=1; i<10; i++)
    {
      if (a[i] < *min)
	*min = a[i];
    }
}


