Ex - No:01 Matrix Multiplication: Aim: Sample Input and Output

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Ex.

No:01
MATRIX MULTIPLICATION
AIM:
To write a C++ program for matrix multiplication using 2-D array.

SAMPLE INPUT AND OUTPUT:


Enter number of rows and columns:
33
Enter first matrix elements:
111
222
333
Enter second matrix elements:
111
222
333
The product of two matrices:
6 66
12 12 12
18 18 18

PROGRAM:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
inti,k,j,A[5][5],B[5][5],C[5][5],r,c,sum=0;
cout<<"Enter number of rows and columns:";
cin>>r>>c;
cout<<"Enter first matrix elements:";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>A[i][j];
}
}
cout<<"Enter second matrix elements:";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>B[i][j];
OUTPUT:
Enter number of rows and columns:
33
Enter first matrix elements:
123
345
567
Enter second matrix elements:
789
923
145
The product of two matrices:
28 24 30
62 52 64
96 80 98
}
}
cout<<"The product of two matrices:"<<"\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
for( k=0;k<r;k++)
sum=sum+A[i][k]*B[k][j];
C[i][j]=sum;
sum=0;
}
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
cout<<C[i][j]<<"\t";
cout<<"\n";
}
getch();
}

RESULT:Thus the given program is executed successfully and the output is verified.

You might also like