100% found this document useful (1 vote)
69 views3 pages

Transpose of Matrix in C Program

The document contains a C program that transposes a given matrix. It prompts the user to input the number of rows and columns, then collects the matrix data, displays the original matrix, and finally prints its transpose. The program uses nested loops to handle the matrix operations.

Uploaded by

cscience424
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
69 views3 pages

Transpose of Matrix in C Program

The document contains a C program that transposes a given matrix. It prompts the user to input the number of rows and columns, then collects the matrix data, displays the original matrix, and finally prints its transpose. The program uses nested loops to handle the matrix operations.

Uploaded by

cscience424
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

//Transpose of matrix

#include <stdio.h>

int main() {
int r,c,i,j,a[10][10],b[10][10];
printf("Enter no of rows:");
scanf("%d",&r);
printf("Enter no of columns:");
scanf("%d",&c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("Enter data in a[%d][%d]:",i,j);
scanf("%d",&a[i][j]);
}
}
printf("The given matrix is \n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
b[i][j]=a[j][i];

}
printf("\n");
}

printf("The transpose of the given matrix is \n");


for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",b[i][j]);

}
printf("\n");
}
return 0;
}

OUTPUT:
Enter no of rows:2
Enter no of columns:2
Enter data in a[0][0]:1
Enter data in a[0][1]:2
Enter data in a[1][0]:3
Enter data in a[1][1]:4
The given matrix is
1 2
3 4

The transpose of the given matrix is


1 3
2 4

You might also like