0% found this document useful (0 votes)
28 views4 pages

Matrix PRGM

The document provides a C program for multiplying two matrices of sizes 2x3 and 3x4, resulting in a 2x4 matrix. It includes steps for inputting the matrix elements, performing the multiplication, and displaying the results. Additionally, it explains the prerequisite for matrix multiplication and how to compute the elements of the resultant matrix manually.

Uploaded by

soumyamkdesai40
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)
28 views4 pages

Matrix PRGM

The document provides a C program for multiplying two matrices of sizes 2x3 and 3x4, resulting in a 2x4 matrix. It includes steps for inputting the matrix elements, performing the multiplication, and displaying the results. Additionally, it explains the prerequisite for matrix multiplication and how to compute the elements of the resultant matrix manually.

Uploaded by

soumyamkdesai40
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/ 4

C program for multiplying the two matrices:-

#include<stdio.h>
#include<conio.h>
void main()
{
int a[2][3], b[3][4], c[2][4];
int i,j,k;
printf("Enter elements of the first matrix of order 2 x 3 \n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter elements of the second matrix of order 3 x 4 \n");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\nFirst Matrix is \n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("\nSecond Matrix is \n");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("\nMatrix multiplication is \n");
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}

Multiplying two matrices

A prerequisite for multiplying two matrices is that the number of columns in the
first matrix must be equal to the number of rows in the second matrix.

Steps:-

1. Create two matrices of orders 2 x 3 and 3 x 4 each.


2. Before we make the matrix multiplication program, we need to understand
how matrix multiplication is performed manually. To do so, let's assume that
the two matrices to be multiplied have the following elements:
3. The resultant matrix will be of the order 2 x 4, that is, the resultant matrix
will have the same number of rows as the first matrix and the same number
of columns as the second matrix:

4. The element first row, first column in the resultant matrix is computed
using the following formula:
SUM(first element of the first row of the first matrix × first element of the first
column of the second matrix), (second element of the first row... × second element
of the first column...), (and so on...)

For example, let's assume the elements of the two matrices .The elements in the
first row and the first column of the resultant matrix will be computed as follows:
5. Hence, the element in first row, first column in the resultant matrix will be
as follows:
(3×6)+(9×3)+(7×5)
=18 + 27 + 35
=80

You might also like