1. Write a C program to find the transpose of a matrix.
– June 2022
#include <stdio.h>
int main() {
int rows, cols;
// Input matrix size
printf("Enter the number of rows and columns of the matrix: ");
scanf("%d %d", &rows, &cols);
int matrix[rows][cols], transpose[rows][cols];
// Input matrix elements
printf("Enter the elements of the matrix:\n");
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
scanf("%d", &matrix[i][j]);
// Compute the transpose of the matrix
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
transpose[j][i] = matrix[i][j];
// Print the transpose of the matrix
printf("The transpose of the matrix is:\n");
for (int i = 0; i < cols; i++)
{ // Rows and columns are swapped
for (int j = 0; j < rows; j++)
printf("%d ", transpose[i][j]);
printf("\n");
return 0;
2. Write a C program to accept a 2 D integer matrix and check whether it is symmetric or not
(A matrix ‘A’ is symmetric if A = AT ). – June 2023
#include <stdio.h>
int main() {
int size;
// Input matrix size
printf("Enter the size of a square matrix: ");
scanf("%d",&size);
int matrix[size][size], transpose[size][size],flag=0;
// Input matrix elements
printf("Enter the elements of the matrix:\n");
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
scanf("%d", &matrix[i][j]);
// Compute the transpose of the matrix
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
{
transpose[j][i] = matrix[i][j];
for (int i = 0; i < size; i++)
{ // Rows and columns are swapped
for (int j = 0; j < size; j++)
if(matrix[i][j] != transpose[i][j])
flag=1;
break;
if(flag)
break;
if(flag==0)
printf("The matrix is a symmetric matrix");
else
printf("The matrix is not a symmetric matrix");
return 0;