CSCI 152 Introduction to Computer Science
Lab 7
  

Objectives:
two-dimensional arrays and functions

Lab Practice

  1. Program 1 :
    Write a function void ReadArray (int A[ ][COL], int num_row, int num_col) that reads a two dimensional array, COL - is the number of columns in array A. Write a function int even (int A[][COL], int num_rows, int num_cols) that finds and returns the amount of the even elements among the elements of the array A. Write a program that reads five two-dimensional arrays of size 3X4 (3 rows and 4 columns) each and find an array that has a maximal amount of the even elements. Use function even to count the amount of even elements in each array and use function ReadArray to read an input. Try to declare only one two-dimensional array and re-use this memory space 5 times by using loop structure.

  2. Program 2 :
    Write a function void fillRandom(int A[ ][COL], int num_rows, int num_cols) that fills the array A with the random numbers between 0 and 4 (including 0 and 4). Write a program that performs the following:

  3. Program 3:
    Write a function int numNonZero(int A[][COL], int num_rows, int num_cols, int i, int j) that finds and returns the amount of non-zero neighbours elements of the element (i, j) of the two-dimensional array A. Write a program that reads one two-dimensional array of size 3X4 and for prints the amount of non-zero neighbours for each location in the array.

  4. Program 4 :
    Write a function void fillRandom(int A[ ][COL], int num_rows, int num_cols) that fills the array A with the random numbers between -3 and 3 (including -3 and 3). Write a function int numNonZero(int A[][COL], int num_rows, int num_cols) that finds and returns the amount of non-zero elements of the array A. Write a program that performs the following:

  5. Program 5 : Selection Sort:
    Write a program that sorts the array of integers using Selection Sort.
    Definition: Selection Sort works as follows: first find the Problem 4: Selection Sort:
    Write a program that sorts the array of integers using Selection Sort.
    Definition: Selection Sort works as follows: first find the smallest element in the array and exchange it with the element in the first position, then find the second smallest element and exchange it with the element in the second position, and continue in this way until the entire array is sorted. You would need to write the following functions:

  6. Problem 6: Write the following functions: