Write C only not C Write a C program that creates an Integer
(Write C only, not C++)
Write a C program that creates an Integer matrix M by N elements (M and N are read from the user). Read matrix elements and print the original matrix on the screen. Print the transpose matrix (rows and columns are switched). Using functions. Output example: Matrix sizes: 3 2 Element[0][0] = 1 Element[0][1] = 8 Elemental [1][0] = 3 Element[1][1] = 4 Element[2][0] = 5 Element[2][1] = Original matrix: 1 2 3 4 5 6 Transpose matrix: 1 3 5 2 4 6Solution
#include <stdio.h>
int main()
{
int orignalMatrix[10][10], transposeMatrix[10][10], m, n, i, j;
printf(\"Matrix sizes: \");
scanf(\"%d %d\", &m, &n);//storing the sizes of matrix
//storin orignal matrix elements
for(i=0; i<m; ++i){
for(j=0; j<n; ++j)
{
printf(\"Element[%d][%d]= \",i, j);
scanf(\"%d\", &orignalMatrix[i][j]);
}
}
// Displaying the orignal matrix */
printf(\"\\Orignal Matrix: \ \");
for(i=0; i<m; ++i){
for(j=0; j<n; ++j)
{
printf(\"%d \", orignalMatrix[i][j]);
}
printf(\"\ \");
}
for(i=0; i<m; ++i){
for(j=0; j<n; ++j)
{
printf(\"%d \",orignalMatrix[i][j]);
transposeMatrix[j][i] = orignalMatrix[i][j];
}
printf(\"\ \");
}
// Displaying the transpose of matrix a
printf(\"\ Transpose of Matrix:\ \");
for(i=0; i<n; ++i){
for(j=0; j<m; ++j)
{
printf(\"%d \",transposeMatrix[i][j]);
}
printf(\"\ \");
}
return 0;
}
------------------------------------------------------
output:
Matrix sizes: 2
3
Element[0][0]= 1
Element[0][1]= 2
Element[0][2]= 3
Element[1][0]= 4
Element[1][1]= 5
Element[1][2]= 6
Orignal Matrix:
1 2 3
4 5 6
1 2 3
4 5 6
Transpose of Matrix:
1 4
2 5
3 6
Process returned 0 (0x0) execution time : 5.653 s
Press any key to continue.

