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

Ex - No:01 Matrix Multiplication: Aim: Sample Inpiut and Output: Program

This document contains a C++ program to perform matrix multiplication using 2D arrays. The program takes the number of rows and columns as input, then inputs the elements of two matrices. It initializes a third matrix to store the product. The program uses a nested for loop to iterate through the matrices and calculate the sum of multiplications of corresponding elements, storing the results in the third matrix. Finally, it prints the output matrix to verify correct execution.

Uploaded by

Gautham
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 Inpiut and Output: Program

This document contains a C++ program to perform matrix multiplication using 2D arrays. The program takes the number of rows and columns as input, then inputs the elements of two matrices. It initializes a third matrix to store the product. The program uses a nested for loop to iterate through the matrices and calculate the sum of multiplications of corresponding elements, storing the results in the third matrix. Finally, it prints the output matrix to verify correct execution.

Uploaded by

Gautham
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 INPIUT AND OUTPUT:

PROGRAM:

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int i,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];

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.
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

You might also like