0% found this document useful (0 votes)
10 views3 pages

Lab 7 & 8 Tasks

Uploaded by

hamziproboi
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)
10 views3 pages

Lab 7 & 8 Tasks

Uploaded by

hamziproboi
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/ 3

Task # 01: Transpose a 2D Matrix

Matrix Creation in Main Function:

- Create a 2D array in the main function with dimensions entered by the user (rows x
cols).
- Prompt the user to input the elements of the matrix.

Original Matrix Traversal and Display (in Main):

- Traverse and print the original matrix using nested loops, directly in the main function.

Transpose Using a User-Defined Function:

- Write a function named transposeArray that takes the original array

- Uses nested loops to compute the transpose of the matrix by swapping rows and
columns. (Hint: transposed[j][i] = array[i][j])

Transposed Matrix Traversal and Display (in Main):

- Traverse and print the transposed matrix using nested loops, directly in the main
function.

Expected Output Example:


Enter the number of rows: 2
Enter the number of columns: 3
Enter the elements of the matrix:
123
456

Original Matrix:
123
456

Transposed Matrix:
14
25
36
Task # 02: Matrix Multiplication Using User-Defined Functions
Matrix Creation in Main Function:

- Create two 2D arrays in the main function: matrixA and matrixB, with user-defined
dimensions.
- Ensure that the number of columns in matrixA equals the number of rows in matrixB
- Prompt the user to input the elements of both matrices.

Matrix Traversal and Display:

- Traverse and print both matrixA and matrixB in the main function, using nested loops.

Matrix Multiplication Using a User-Defined Function:

- Write a function named multiplyMatrices that:


- Takes both matrices (matrixA and matrixB) and their dimensions as inputs.
- Computes their product and stores the result in a third matrix, resultMatrix.
- Uses the formula for matrix multiplication:
resultMatrix[i][j] = sum(matrixA[i][k] matrixB[k][j]) for k in range of p,
where p is the number of columns in matrixA (or rows in matrixB).

Return the Resultant Matrix:

- Return the resultMatrix from your user-defined function to the main function.

Print the Resultant Matrix:

- In the main function, traverse and print the resultMatrix after the function call.

Expected Output Example:


Enter the number of rows for Matrix A: 2
Enter the number of columns for Matrix A (and rows for Matrix B): 3
Enter the number of columns for Matrix B: 2

Enter the elements of Matrix A:


123
456

Enter the elements of Matrix B:


78
9 10
11 12

Matrix A:
123
456

Matrix B:
78
9 10
11 12

Resultant Matrix:
58 64
139 154

You might also like