Chapter - 9: Arrays

Write a program to obtain transpose of a 4 x 4 matrix. The transpose of a matrix is obtained by exchanging the elements of each row with the elements of the corresponding column.


L
Sections
3
Exercises

A

B

C

D

E

F

G

H

I

J

K

L

1

2

3

4

5

6

7

8

9

10

11

13

14

15

16

17

18

19

#include<stdio.h>
#include<conio.h>
int main()
{
	int mat[4][4], tran[4][4];
	int i, j;

	printf("Enter the elements of the 4 by 4 matrix\n");
	for (i = 0; i<4; i++)//scanning matrix
		for (j = 0; j<4; j++)
			scanf("%d", &mat[i][j]);

	for (i = 0; i<4; i++)//finding transpose of the martrix
		for (j = 0; j<4; j++)
			tran[i][j] = mat[j][i];

	for (i = 0; i < 4; i++)//printing transpose of the matrix
	{
		for (j = 0; j < 4; j++)
			printf("%d ", tran[i][j]);
		printf("\n");
	}

	_getch();
	return 0;
}

© 2020 Garbage Valuegarbage value logo