Array Review Homework

  1. Write a function called hotDays. An array of daily temperatures and the size of the array are passed to the function. The function should return the number of hot days in the array. A day is hot if the temperature is 85 or higher.
  2. Write the statements to call hotDays and print the number of hot days.
  3. Write the statements to add 10 to each entry of the array values. Assume that values is an int array with 40 elements.
  4. Write a function called initRow that initializes the elements in one row of a 2D array to zero. The parameters to the function are the array, the number of columns, and the row which should be initialized. Assume the array is declared in main to have MAXROWS rows and MAXCOLS columns.
  5. Write the statements to declare a 2D array of ints with 10 rows and 20 columns, and then call initRow to initialize all rows of the array.
  6. Write a function which returns the smallest and largest values in a 2D array. The array, the number of columns, and the number of rows are passed as parms. Assume the array is declared in main to have MAXROWS rows and MAXCOLS columns.
  7. Write a function called add that takes two parallel arrays A and B and the size of the arrays as parameters. The function should return the sum of the elements of B whose corresponding element of A is less than zero.
  8. What is wrong with the following statements:
          int arr[5][4];
          for (int i = 0 ; i < 4 ; i++)
             for (int j = 0 ; j < 5 ; j++)
                arr[i][j] = i + j;
    
  9. Write the statements to print out an array of 25 ints in reverse order.

Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2003