Q:

C PROGRAM FOR MATRIX ADDITION

0

C PROGRAM FOR MATRIX ADDITION

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

int main()

{

int a, b, c, d;

int m1[10][10], m2[10][10], sum[10][10];

 

printf(“Please enter the number of rows of matrix\n”);

scanf(“%d”, &a);

printf(“Please enter number of columns of matrix\n”);

scanf(“%d”, &b);

printf(“Please enter the elements of first matrix one by one\n”);

 

for ( c = 0 ; c < a ; c++ )

{

for ( d = 0 ; d < b ; d++ )

{

scanf(“%d”, &m1[c][d]);

}

}

printf(“Please enter the elements of second matrix one by one\n”);

 

for ( c = 0 ; c < a ; c++ )

{

for ( d = 0 ; d < b ; d++ )

{

scanf(“%d”, &m2[c][d]);

}

}

 

for ( c = 0 ; c < a ; c++ )

{

for ( d = 0 ; d < b ; d++ )

{

sum[c][d] = m1[c][d] + m2[c][d];

}

}

 

printf(“The sum of entered matrices is below:\n”);

 

for ( c = 0 ; c < a ; c++ )

{

for ( d = 0 ; d < b ; d++ )

printf(“%d\t”, sum[c][d]);

 

printf(“\n”);

}

return 0;

}

Output:

Please enter the number of rows of matrix

2

Please enter number of columns of matrix

2

Please enter the elements of first matrix one by one

3

3

3

3

Please enter the elements of second matrix one by one

4

4

4

4

The sum of entered matrices is below:

7    7

7    7

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now