0% found this document useful (0 votes)
11 views2 pages

C Program for 2x2 Matrix Multiplication

Uploaded by

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

C Program for 2x2 Matrix Multiplication

Uploaded by

truptiadhav33
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <stdio.

h>
int main() {
int a[2][2], b[2][2], c[2][2];
int i, j, k, n, m, p, q;
// Input first matrix
printf("Enter elements of first matrix:\n");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
scanf("%d", &a[i][j]);
// Input second matrix
printf("Enter elements of second matrix:\n");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
scanf("%d", &b[i][j]);

// Multiply
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
c[i][j] = 0;
for (k = 0; k < 2; k++)
{
c[i][j] += a[i][k] * b[k][j];
}
}
}
// Output result
printf("Resultant matrix:\n");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
printf("%d ", c[i][j]);
printf("\n");
}
return 0;
}

Output-----------------------------------------------------------------------------------
Enter elements of first matrix:

12

34

Enter elements of second matrix:

56

78

Resultant matrix:

19 22

43 50

You might also like