Read an integer array and then do linear searches.

*     MYCPLUS Sample Code -     *
*                                                     *
*   This code is made available as a service to our   *
*      visitors and is provided strictly for the      *
*               purpose of illustration.              *
*                                                     *
* Please direct all inquiries to saqib at *


#define NMAX 10

int getIntArray(int a[], int nmax, int sentinel);
void printIntArray(int a[], int n);
int linear(int a[], int n, int who);

int main(void) {
  int x[NMAX];
  int hmny;
  int who;
  int where;

  hmny = getIntArray(x, NMAX, 0);
  printf("The array was: \n");
  printf("Now we do linear searches on this data\n");
    printf("Enter integer to search for [0 to terminate] : ");
    scanf("%d", &who);
    where = linear(x,hmny,who);
    if (where<0){
      printf("Sorry, %d is not in the array\n",who);
      printf("%d is at position %d\n",who,where);

void printIntArray(int a[], int n)
     /* n is the number of elements in the array a.
      * These values are printed out, five per line. */
  int i;

  for (i=0; i