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

Dsa Lab Task 3

1) The document is a student submission for a data structures lab assignment at SZABIST-ISB. 2) The assignment asks the student to write C++ code to multiply two 3x3 matrices and output the product matrix. 3) The student's code defines two 3x3 input matrices, initializes a third product matrix, uses a nested for loop to calculate the dot product of each row and column to populate the product matrix, and outputs the two input and one product matrix.

Uploaded by

syed usama
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)
35 views3 pages

Dsa Lab Task 3

1) The document is a student submission for a data structures lab assignment at SZABIST-ISB. 2) The assignment asks the student to write C++ code to multiply two 3x3 matrices and output the product matrix. 3) The student's code defines two 3x3 input matrices, initializes a third product matrix, uses a nested for loop to calculate the dot product of each row and column to populate the product matrix, and outputs the two input and one product matrix.

Uploaded by

syed usama
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

Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Total Marks:

Obtained Marks:

Data Structure Lab


Task

Submitted To: Ms. Tehreem Saboor


_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Student Name: Syed Usama Amjad


_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Reg Number: 2180134


_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

DSA(LAB) BS(SE)-3-A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Q) Answer:
Code:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int mat1 [3][3], mat2[3][3],mat3[3][3], i ,j, k, sum;

cout<<"\nEnter values for first 3 x 3 matrix:\n";


for ( i = 0 ; i <= 2 ; i++ )
{
for (j = 0 ; j <= 2 ; j++ )
cin>>mat1 [i][j] ;
}
cout<<"\n Enter values for second 3 x 3 matrix:\n";
for ( i = 0 ; i <= 2 ; i++ )
{
for ( j = 0 ; j <= 2 ; j++ )
cin>>mat2[i][j] ;
}
cout<<"\n The first 3 x 3 matrix entered by you is:\n";
for ( i = 0 ; i <= 2 ; i++ )
{
for ( j = 0 ; j <= 2 ; j++ )
cout<<"\t"<< mat1[i][j] ;
cout<<"\n";
}
cout<<"\n the second 3 x 3 matrix entered :\n";
for ( i = 0 ; i <= 2 ; i++ )
{
for ( j = 0 ; j <= 2 ; j++ )
cout<<"\t"<< mat2[i][j] ;
cout<<"\n";
}
for ( i = 0 ; i <= 2 ; i++ )
{
for ( j = 0 ; j <= 2 ; j++ )
{
sum = 0;
for ( k = 0 ; k <=2 ; k++ )
sum = sum + mat1 [i][k] * mat2[k][j];
mat3[i][j] = sum ;
}
}

DSA(LAB) BS(SE)-3-A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

cout<<"\nThe product of the above two matrices is:\n";


for ( i = 0 ;i<= 2 ; i++ )
{
for ( j = 0 ; j <= 2 ; j++ )
cout<<"\t"<<mat3[i][j] ;
cout<<"\n";
}
cout<<"\n Press any key to exit.";
getch( ) ;
}

Output / Screenshot:

DSA(LAB) BS(SE)-3-A SZABIST-ISB

You might also like