0% found this document useful (0 votes)
30 views3 pages

Write A C Program To Find The Transpose of A Matrix

The document contains two C programs: the first program computes the transpose of a matrix, while the second checks if a square matrix is symmetric. Both programs involve user input for matrix dimensions and elements, followed by calculations and output of results. The first program outputs the transposed matrix, and the second program indicates whether the matrix is symmetric or not.

Uploaded by

Roy Sathyadevan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Write A C Program To Find The Transpose of A Matrix

The document contains two C programs: the first program computes the transpose of a matrix, while the second checks if a square matrix is symmetric. Both programs involve user input for matrix dimensions and elements, followed by calculations and output of results. The first program outputs the transposed matrix, and the second program indicates whether the matrix is symmetric or not.

Uploaded by

Roy Sathyadevan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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;

You might also like