Professional Documents
Culture Documents
Ex - No:01 Matrix Multiplication: Aim: Sample Input and Output
Ex - No:01 Matrix Multiplication: Aim: Sample Input and Output
Ex - No:01 Matrix Multiplication: Aim: Sample Input and Output
No:01
MATRIX MULTIPLICATION
AIM:
To write a C++ program for matrix multiplication using 2-D array.
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.