Assignment 5.6 .When a two-dimension (2D) matrix is declared by a C program, the
ID: 3851743 • Letter: A
Question
Assignment 5.6 .When a two-dimension (2D) matrix is declared by a C program, the matrix in fact is stored as a one-dimensional array in the memory. C program uses a row-major approach to convert a 2D matrix into a 1D array. The following gives an example of storing a 3-by-3 matrix in the memory Index (0,0 0, 1 (0, 2) (1,0 ,1) 1, 2) (2, 0) (2, 1) (2, 2) Content 6 Memory offseto 4 12 16 20 24 28 32 in bytes 1 Row 2nd Row 3nd Row Assignment 5.6 Translate the following C program into an assembly program. Your assembly program must consist of two nested loops int a[4][3] 111,12,13), //first row (21, 22, 23), I/ second row (31, 32, 33), // third row {41, 42,43 // fourth row void main(void) int i, j; for(i = 0; iExplanation / Answer
/*source code of addition of 3x3 matrix c program*/
#include<stdio.h>
#include<conio.h>
int main()
{
int matA[3][3],matB[3][3],matC[3][3];
int r,c,k;
for(r=0; r<3; r++)
{
for(c=0; c<3; c++)
{
printf("Enter first matrix : ");
scanf("%d", &matA[r][c]);
}
}
for(r=0; r<3; r++)
{
for(c=0; c<3; c++)
{
printf("Enter second matrix : ");
scanf("%d", &matB[r][c]);
}
}
for(r=0; r<3; r++)
{
for(c=0; c<3; c++)
{
matC[r][c]=0;
for(k=0; k<3;k++)
matC[r][c] = matA[r][c] + matB[r][c];
}
}
printf(" New addition matrix : ");
for(r=0; r<3; r++)
{
for(c=0; c<3; c++)
printf(" %d",matC[r][c]);
printf(" ");
}
getch();
return 0;
}