206k views
4 votes
Write a C program to read the values of a 6 x 6 2D array from a file, and then produce an output file that contains the transpose of the array. Array values are decimal. The input and output files contain one array row on each text line

User Jim Rush
by
7.6k points

1 Answer

3 votes

Answer:

Step-by-step explanation:

#include <stdio.h>

int main()

{

int arr[5][5], trans [5][5], i, j;

// Entering elements to the matrix

printf("\\Enter matrix elements:\\");

for (i = 0; i < 6; ++i)

for (j = 0; j < 6; ++j) {

printf("Enter element a%d%d: ", i + 1, j + 1);

scanf("%d", &arr[i][j]);

}

printf("\\The given input matrix is: \\");

for (i = 0; i < 6; ++i)

for (j = 0; j < 6; ++j) {

printf("%d ", arr[i][j]);

if (j == 5)

printf("\\");

}

// Transpose

for (i = 0; i < 6; ++i)

for (j = 0; j < 6; ++j) {

trans[j][i] = a[i][j];

}

printf("\\The output transpose of the matrix:\\");

for (i = 0; i < 6; ++i)

for (j = 0; j < 6; ++j) {

printf("%d ", trans[i][j]);

if (j == 5)

printf("\\");

}

return 0;

}

User Libbie
by
7.4k points