You are on page 1of 5

Republic of the Philippines

POLYTECHNIC UNIVERSITY OF THE PHILIPPINES


COLLEGE OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

COEN 3054
(DATA STRUCTURES and ALGORITHM)
EXERCISE

2
ARRAYS with FUNCTIONS
Submitted by:
________________________
Submitted to:
________________________
Date Submitted
_________________________

1. In the main function


a. Declare and initialize a two-D array of integers containing 10 rows and 10 columns. The
diagonal cells that run from upper left to lower right contain the integer 1. The other cells contain 0.
b. Prompt the user to enter a row number and a column number - these will be used below.
c. Populate the array as described above using either a for loop or a while loop.
Call a function named printArray that will print the contents of the array, 10 numbers per
line
Call a function named printCol that will print the contents of the col number referenced
above, one item per line. Do this using a for or a while loop- and any other structures
needed.
Call a function named printRow that will print the contents of the row number referenced
above, all on one line with a space between each. Do this using a for or a while loop - and
any other structures needed.
Call a function named printDiagonal that will print the numbers on the diagonal, all on the
same line, with a space between. Do this using a for or a while loop - and any other
structures needed.

2. In the main function, declare and populate a 2 D array of integers with the
following numbers in the rows and columns as indicated
1234
4321
5678
8765
a. Call a function named PrintArray and pass the above array. The function will print
the array by line, appropriately labeled
b. Call a function named FindSum and pass the above array. The function will find
the sum of the numbers in the array and print it, appropriately labeled.

CUT AND PASTE THE SOURCE CODE AND CAPTURED OUTPUT SCREEN HERE.

Problem 3:
1. In the main function, create a 10 x 8 two dimensional array consisting of random integers in the
range 50 to 99, including the end points
2. Call a function named printArray that will print the array, appropriately labeled, 8 numbers per
line, with a space between each
3. Call a function named findSmallest that will find and print, appropriately labeled, the smallest
number in the array
4. Call a function named findAverage that will find and print, appropriately labeled, the average of
the numbers in the array
5. Call a function named findMode that will find and print, appropriately labeled, the number that
occurs most often. It there are ties, print only 1
6. Call a function named removeEvens, that will modify the array such that all even numbers are
replaced by the number 11
7. Call the function named printArray discussed in part 2 above and print the array as modified in
part 6 above.

CUT AND PASTE THE SOURCE CODE AND CAPTURED OUTPUT SCREEN HERE

You might also like