Computer Science, asked by chokletboyranad4317, 9 months ago

In Hackerland every character has a weight. The weight of an English uppercase alphabet A-Z is given below : A = 1 B = 2*A + A

Answers

Answered by Anonymous
2

Search Programiz

C Program to Find Transpose of a Matrix

C Program to Find Transpose of a Matrix

In this example, you will learn to find the transpose of a matrix in C programming.

To understand this example, you should have the knowledge of the following C programming topics:

C Arrays

C Multidimensional Arrays

The transpose of a matrix is a new matrix that is obtained by exchanging the rows and columns.

In this program, the user is asked to enter the number of rows r and columns c. Their values should be less than 10 in this program.

Then, the user is asked to enter the elements of the matrix (of order r*c).

The program below then computes the transpose of the matrix and prints it on the screen.

Program to Find the Transpose of a Matrix

#include <stdio.h>

int main() {

int a[10][10], transpose[10][10], r, c, i, j;

printf("Enter rows and columns: ");

scanf("%d %d", &r, &c);

// Assigning elements to the matrix

printf("\nEnter matrix elements:\n");

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

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

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

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

}

// Displaying the matrix a[][]

printf("\nEntered matrix: \n");

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

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

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

if (j == c - 1)

printf("\n");

}

// Finding the transpose of matrix a

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

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

transpose[j][i] = a[i][j];

}

// Displaying the transpose of matrix a

printf("\nTranspose of the matrix:\n");

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

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

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

if (j == r - 1)

printf("\n");

}

return 0;

}

Similar questions