DAA Assignment 1
DAA Assignment 1
procedure MatrixMultiplication(A, B)
input A, B n*n matrix
output C, n*n matrix
begin
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
C[i, j] = 0;
end for
end for
#include <stdio.h>
scanf("%d", &matrix[i][j]);
int matrixMultiply(int A[][10], int r1, int c1, int B[][10], int r2, int c2, int C[][10]) {
if (c1 != r2) {
return 0;
C[i][j] = 0;
return 1;
printf("\n");
int main() {
printf("Enter the number of rows and columns for the first matrix (A): ");
printf("Enter the number of rows and columns for the second matrix (B): ");
if (c1 != r2) {
return 1;
return 0;
}
Addition: n3 −n2
For each element in the result matrix, after performing n multiplications, n−1
additions are needed to sum the products. Since there are n^2 elements in the
result matrix, the total number of additions is n2×(n−1)=n3−n^2
Multiplication: n3
In matrix multiplication, each element in the result matrix is obtained by
multiplying n elements from a row of the first matrix and a column of the
second matrix. For an n×n matrix, there are n^2 elements in the result matrix,
and each element requires n multiplications. Thus, the total number of
multiplications is n^3.
Total: 2 n3−n2
The total arithmetic operations required combine both multiplication (n^3)
and addition (n^3 - n^2), resulting in:
Total Operations=n3+(n3−n2)=2n3−n2