C program for matrix addition

C program for matrix addition:

#include <stdio.h>

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


Share this website !!!
Facebook Twitter Linkedin