You are on page 1of 6

Student Name:SUPARN GAUTAM UID: 20BCS3671

Branch: CSE(I.S.) Section/Group:ON20BIS/B


Semester: 04 Date of Performance:24/03/2022
Subject Name: DAA LAB Subject Code: 20CSP-285

1. Aim/Overview of the practical:


WS5 You have been given two matrices of size 32x32. Write a program to find multiplication of these
matrices using traditional method of multiplication which uses divide and conquer technique.

2. Algorithm:

 Start
 Input the no. of rows and columns of both the elements.
 Check if the number of columns of first matrix is same as the rows  of second matrix which
is condition for matrix multiplication.
 Applying for loops, use the formula Cij = ∑(Aik * Bik)  where, i,j,k are positive integers
and i,j,k<=n
 Next, we display the final matrix.
 End
3. CODE for given problem:

#include <iostream>
using namespace std;
void multiply(int[32][32], int[32][32], int, int, int);
int display(int[32][32], int, int);
int main()
{

int a[32][32], b[32][32], r1, c1, r2, c2;


cout<<"\nRows of 1st matrix: ";
cin>>r1;
cout<<"******************************************";
cout<<"\nColumns of 1st matrix: ";
cin>>c1;

cout<<"\nRows of 2nd matrix: ";


cin>>r2;
cout<<"\nColumns of 2nd matrix:";
cin>>c2;

if (c1 != r2)
return 0;

cout<<"\nProvide elements of 1st matrix:: \n";

for(int i=0; i<r1; i++)


{
for(int j=0; j<c1; j++)
cin>>a[i][j];
}
cout<<"\nProvide elements of 2nd matrix:: \n";

for(int i=0; i<r2; i++)


{
for(int j=0; j<c2; j++)
cin>>b[i][j];
}
display(a,r1,c1);
display(b,r2,c2);

multiply(a, b, r1, c2, c1);


return 0;
}

void multiply(int a[32][32], int b[32][32], int row, int col, int c1)
{
int c[32][32];

for(int i=0; i<row; i++)


{
for(int j=0; j<col; j++)
c[i][j]=0;
}

for(int i=0; i<row; i++)


{
for(int j=0; j<col; j++)
{
for(int k=0; k<c1; k++)
c[i][j]+=a[i][k]*b[k][j];
}
}

cout<<"\n Resultant matrix C after multiplying two matrices is:\n";


display(c, row, col);
}
int display(int c[32][32], int row, int col)
{
cout<<"\n Matrix is:\n";
for(int i=0; i<row; i++)
{
for(int j=0; j<col; j++)
cout<<c[i][j]<<" ";
cout<<"\n";
}
return 0;
}

4. Screenshot of code:
5.Output:

Learning outcomes (What I have learnt):

1.

2.

3.

4.

5.

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):
Sr. No. Parameters Marks Obtained Maximum Marks
1.
2.
3.

You might also like