0% found this document useful (0 votes)
131 views5 pages

COEN 3054 - Lab Exercise No. 2 - Arrays With Functions

This document provides instructions for exercises involving arrays and functions in C programming. It includes 3 problems to write code for: 1) Declaring and populating 2D arrays, then calling functions to print rows, columns, diagonals of the array. 2) Declaring and populating another 2D array, then calling functions to print and find the sum of the array. 3) Declaring a random 2D array, then calling functions to print the array, find smallest/average/most common values, replace evens with 11, and reprint the array. Students are to copy their code and output for each problem into the document.

Uploaded by

Abby Orioque II
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views5 pages

COEN 3054 - Lab Exercise No. 2 - Arrays With Functions

This document provides instructions for exercises involving arrays and functions in C programming. It includes 3 problems to write code for: 1) Declaring and populating 2D arrays, then calling functions to print rows, columns, diagonals of the array. 2) Declaring and populating another 2D array, then calling functions to print and find the sum of the array. 3) Declaring a random 2D array, then calling functions to print the array, find smallest/average/most common values, replace evens with 11, and reprint the array. Students are to copy their code and output for each problem into the document.

Uploaded by

Abby Orioque II
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy