Instructions
User Manual:
Open the PDF directly: View PDF
.
Page Count: 4

ITCS 201 – Fundamentals of Programming
Week 9: Lab Assignments
Name: _________________________________________ ID: ________________
Due: today or in a lab session next week
Instructions:
- Marking lab assignments will be done in the lab
- Compile and Run your program
- Show and Explain the output to the lecturer or the lab assistance.
---------------------------------------- Lab Assignments -----------------------------------
In this assignment, you need to write C programs for the following problems.
Lab 1: Declare a 2-D array with 3 rows and 4 columns. Then randomly assign the
array with 12 integers with the values between 0 and 9, inclusive. Then, print the
contents of the array, with 3 rows and 4 columns. For readability, you should include
a space between each number. The output should look like the following, with the
x's representing numbers in the array.
Example output:
x x x x
x x x x
x x x x
You may use the following code to get a random integer between 0 and 9.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main() {
// Initialization, should only be called once.
srand(time(NULL));
// Random an integer between 0 and 9
int rand_number = rand() % 10;
printf("Random number: %d\n", rand_number);
return 0;
}

Lab 2: Extend the Lab 1 to also compute the sum of each row and each column.
Specifically, after the 2-D array has been randomly initialized with 12 integers, your
program will then compute the sum of each row and each column, and print out the
output.
For example, if the 2-D array is randomly initialized with the following values:
5
3
3
6
2
1
2
7
3
0
4
8
The expected output should be as shown below:
Example output:
Sum of rows: 17 12 15
Sum of columns: 10 4 9 21

Bonus Questions
Bonus Lab: Write a program to determine whether an input square matrix is
symmetric. First the program will ask a user to input the number of row and column
of the matrix. It should print out an error when the number of rows and columns are
not equal (i.e., not a square matrix). Then the program will ask the user to enter the
value of each element in the matrix. Finally, the program will print out whether an
input square matrix is symmetric or not.
• If the matrix is symmetric, the program should print out:
“The matrix is a symmetric”.
• If the matrix is not symmetric, the program should print out:
“The matrix is not a symmetric”.
Note: The maximum number of row and column is 5.
Example output:
Enter the number of rows and columns: 3 4
The matrix must be a square matrix.
Enter the number of rows and columns: 3 3
Enter element 0,0: 1
Enter element 0,1: 2
Enter element 0,2: 3
Enter element 1,0: 2
Enter element 1,1: 1
Enter element 1,2: 5
Enter element 2,0: 3
Enter element 2,1: 5
Enter element 2,2: 1
The matrix is symmetric.
Enter the number of rows and columns: 3 3
Enter element 0,0: 0
Enter element 0,1: 0
Enter element 0,2: 0
Enter element 1,0: 1

Enter element 1,1: 1
Enter element 1,2: 1
Enter element 2,0: 2
Enter element 2,1: 2
Enter element 2,2: 2
The matrix is not symmetric.