QUESTION:- write a program using a two-dimensional array to print the sum of the used input matrix and change them from a row to a column.
#include <stdio.h>
void main()
{
int m, n, a[5][5], b[5][5], i, j, sum[5][5];
printf("enter a value of mattrix: ");
scanf("%d %d", &m, &n);
// enter the element of first matrix
printf("enter a first %d x %d matrix: \n", m, n);
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
scanf("%d", &a[i][j]);
}
}
// enter the elements of second matrix
printf("enter the second %d x %d matrix: ", m, n);
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
scanf("%d", &b[i][j]);
}
}
// display the sum
printf("the sum of given matrix are : \n" );
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
sum[i][j] = a[i][j] + b[i][j];
printf("%d ", sum[i][j]);
}
printf("\n");
}
// transpose
printf("the transpose of given matrix are : \n" );
for(j=0; j<n; j++)
{
for(i =0; i<m; i++)
{
printf("%d ", sum[i][j]);
}
printf("\n");
}
}
OUTPUT
enter a first 2 x 3 matrix:
2 5 8
1 4 7
enter the second 2 x 3 matrix: 3 6 9
7 8 9
the sum of a given matrix is:
5 11 17
8 12 16
the transpose of a given matrix is:
5 8
11 12
17 16
0 Comments