QUESTION:- write a program using 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 value of matrix: 2 3
enter a first 2 x 3 matrix:
1 4 7
2 5 8
enter the second 2 x 3 matrix: 3 6 9
2 5 8
the sum of the given matrix is:
4 10 16
4 10 16
the transpose of a given matrix is:
4 4
10 10
16 16
0 Comments