Answers for "dynamically transpose a matrix in c"

C
1

dynamically create matrix c

int **A = (int **)malloc(N * sizeof(int*));

for(i=0; i<N; i++){
    A[i] = (int *)malloc(N * sizeof(int));
}
Posted by: Guest on April-29-2021
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:nn");
  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 "C"

Browse Popular Code Answers by Language