0% found this document useful (0 votes)
5 views

Lab Report 2 ..SM

4

Uploaded by

jullijanam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab Report 2 ..SM

4

Uploaded by

jullijanam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Data Structure and Algorithms

CSE0613104

Lab report - 2
Submitted by
Name: Sunit Mondol
ID:2241081161
Section:61 E
Session: Fall 24

Submitted To
REHNUMA HAQUE
Lecturer, Department of CSE
Uttara University

Submission Date:10 Sep 2024


❖ Question 1: Implement a 2D-array with some random
integer values. Display/print the content.
➢ Answer:
#include<stdio.h>
int main()
{
int A[2][3]={{2,3,4,},{5,6,7}};
int i,j;

printf("The 2D Array as Matrix:\n");


for (i=0;i<2;i++)
{ for (j=0;j<3;j++)
{ printf(" %d ",A[i][j]); }
printf("\n\n");
}
}
✓ Output:

Page | 1
❖ Question 2: Declare two Matrices A [2] [3] = {1, 2, 3, 4, 5, 6}
&amp; B [2] [3] = {1, 2, 1, 2, 1, 2} and store the summation
of A and B into another matrix C [2] [3]. Display/print the
contents of C.
➢ Answer:
#include<stdio.h>
int main()
{ int A[2][3]={{1,2,3,},{4,5,6}};
int B[2][3]={{1,2,1},{2,1,2}};
int C[2][3];
int i,j;

for (i=0;i<2;i++)
{ for (j=0;j<3;j++)
{ C[i][j]=A[i][j]+B[i][j]; }
}
printf("The Matrix C[2][3]:\n");
for (i=0;i<2;i++)
{ for (j=0;j<3;j++)
{ printf(" %d ",C[i][j]); }
printf("\n\n");
}
}
✓ Output:

Page | 2
❖ Question 3 : Declare two Matrices A [2] [3] = {1, 2, 3, 4, 5,
6} &amp; B [3] [2] = {1, 2, 1, 2, 1, 2} and multiply them and
print the resultant matrix C.
➢ Answer:
#include<stdio.h>
int main()
{ int A[2][3]={{1,2,3,},{4,5,6}};
int B[3][2]={{1,2},{1,2},{1,2}};
int C[2][2];
int i,j,k;
for (i=0;i<2;i++)
{ for (j=0;j<2;j++)
{ C[i][j]=0; }
}
for (i=0;i<2;i++)
{ for (j=0;j<2;j++)
{ for (k=0;k<3;k++)
{ C[i][j]+=A[i][k]*B[k][j]; }
}
}
printf("The Matrix C:\n");
for (i=0;i<2;i++)
{ for (j=0;j<2;j++)
{ printf(" %d ",C[i][j]); }
printf("\n\n");
}
}

Page | 3
✓ Output:

Page | 4

You might also like