Answers for "transpose of a matrix in c"

C
1

c program to perform 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;
}
Posted by: Guest on May-31-2020
2

what is transpose of a matrix

The transpose of a matrix is simply a flipped version of 
the original matrix. We can transpose a matrix by switching 
its rows with its columns. We denote the transpose of matrix 
A by AT. For example, if A=[123456] then the transpose of A is 
AT=[142536].
Posted by: Guest on June-20-2020
0

transpose of a matrix in c

#include <stdio.h>

void main()
{
  int a[10][10], transpose[10][10], m, n;
  printf("Enter rows and columns: ");
  scanf("%d %d", &m, &n);


  printf("\nEnter matrix elements:\n\n");
  for (int i = 0; i < m; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
        printf("Enter element a[%d%d]: ",i, j);
        scanf("%d", &a[i][j]);
    }

  }


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

  for (int i = 0; i < m; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
        printf("%d  ", a[i][j]);
        if (j == n - 1)
        printf("\n");
    }
  }

  for (int i = 0; i < m; ++i)
  {
       for (int j = 0; j < n; ++j)
        {
            transpose[j][i] = a[i][j];
        }

  }


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

  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < m; ++j)
    {
        printf("%d  ", transpose[i][j]);
        if (j == m - 1)
        printf("\n");
    }
  }
}
Posted by: Guest on June-25-2021

Code answers related to "transpose of a matrix in c"

Code answers related to "C"

Browse Popular Code Answers by Language