24,411 views
5 votes
5 votes
Problem 1: create an array that represents a 3 X 3 matrix: 1 2 3 4 5 6 7 8 9 Transpose the matrix: 1 4 7 2 5 8 3 6 9 In other words aij  aji Put the transposition operation in a function. Print out the two arrays in main(). Use both matrix [][] operations and perform again with pointers.

User Davia
by
3.2k points

1 Answer

3 votes
3 votes

Answer:

Check the explanation

Step-by-step explanation:

C code:

#include <stdio.h>

void cal_transpose(int arr1[3][3],int transpose[3][3])

{

for (int i = 0; i < 3; ++i)

for (int j = 0; j < 3; ++j) {

transpose[j][i] = arr1[i][j];

}

}

int main()

{

int arr1[3][3]={1,2,3,4,5,6,7,8,9};

int transpose[3][3];

cal_transpose(arr1,transpose);

printf("matrix arr1 : \\");

for (int i = 0; i < 3; ++i)

{ for (int j = 0; j < 3; ++j) {

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

}

printf("\\");

}

printf("Transpose matrix : \\") ;

for (int i = 0; i < 3; ++i)

{

for (int j = 0; j < 3; ++j) {

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

}

printf("\\");

}

return 0;

}

CODE OUTPUT:

Problem 1: create an array that represents a 3 X 3 matrix: 1 2 3 4 5 6 7 8 9 Transpose-example-1
User Haolee
by
3.7k points