0% found this document useful (0 votes)
41 views3 pages

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

The document describes a C++ program to multiply two matrices using 2D arrays. It takes input of the number of rows and columns of the matrices from the user. It then takes the elements of the first and second matrices as input and stores them in 2D arrays. It initializes a third 2D array to store the product matrix. It then calculates the product of corresponding elements of first and second matrices using a nested for loop and stores the results in the third array. Finally, it prints out the product matrix.

Uploaded by

Shyam Sundar
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)
41 views3 pages

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

The document describes a C++ program to multiply two matrices using 2D arrays. It takes input of the number of rows and columns of the matrices from the user. It then takes the elements of the first and second matrices as input and stores them in 2D arrays. It initializes a third 2D array to store the product matrix. It then calculates the product of corresponding elements of first and second matrices using a nested for loop and stores the results in the third array. Finally, it prints out the product matrix.

Uploaded by

Shyam Sundar
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
You are on page 1/ 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