Session 7
Matrix Multiplication in C Using Pointers
This session moves from documentation to implementation. The task is to write a C program for matrix multiplication using pointers, which helps practice memory access and pointer notation in C.
Problem Statement
Write a program in C language for multiplication of two matrices using pointers.
Expected Deliverable
Submit a C program that accepts two compatible matrices, multiplies them using pointer-based access, and prints the result matrix.
Algorithm
- Read matrix dimensions.
- Check whether columns of first matrix equal rows of second matrix.
- Read matrix elements.
- Use three nested loops to compute multiplication.
- Access elements using pointer arithmetic.
- Print the output matrix.
Pointer Access Pattern
*(*(matrix + i) + j)
Complexity
| Metric | Value |
|---|---|
| Time complexity | O(r1 * c2 * c1) |
| Space complexity | O(r1 * c2) for result matrix |
Submission Checklist
- Include source code.
- Include sample input and output.
- Explain pointer notation.
- Handle incompatible matrix dimensions.