Lab Report 2 ..SM
Lab Report 2 ..SM
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
Page | 1
❖ Question 2: Declare two Matrices A [2] [3] = {1, 2, 3, 4, 5, 6}
& 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} & 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