0% found this document useful (0 votes)
15 views1 page

C 7

C Program for transpose of a matrix

Uploaded by

Raju Negi
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
0% found this document useful (0 votes)
15 views1 page

C 7

C Program for transpose of a matrix

Uploaded by

Raju Negi
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

Name-Amit Nautiyal

Class [Link]-14
University [Link]-2401038
Course-MCA
Subject- C Programming

Problem Statement:- Write a c program to find transpose of a matrix

#include <stdio.h>
int main(){
int rows, cols, i, j;
printf("Enter the number of rows: ");
scanf("%d", &rows);
printf("Enter the number of columns: ");
scanf("%d", &cols);
int matrix[rows][cols], transpose[cols][rows];
printf("Enter elements for matrix:\n");
for (i=0; i<rows; i++) {
for (j=0; j<cols; j++) {
printf("Enter element [%d][%d]: ", i, j); scanf("%d", &matrix[i][j]);
}
} for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
transpose[j][i] = matrix[i][j];
}
} printf("\n Original Matrix:\n");
for (i=0; i<rows; i++) {
for (j=0; j<cols; j++) {
printf("%d",matrix[i][j]);
}
printf("\n"); }
printf("Transpose of Matrix:\n");
for(i=0; i<cols; i++) {
for(j = 0; j < rows; j++) {
printf("%d",transpose[i][j]);
}
printf("\n");
}
return 0;
}

Output:
Enter the number of rows: 3
Enter the number of columns: 3 Enter elements of the matrix:
Enter element [0][0]: 9 Enter element [0][1]: 4 Enter element [0][2]: 6
Enter element [1][0]: 3 Enter element [1][1]: 6 Enter element [1][2]: 12
Enter element [2][0]: 7 Enter element [2][1]: 14 Enter element [2][2]: 21

Original Matrix:
9 4 6
3 6 12
7 14 21
Transpose of the Matrix:
9 3 7
4 6 14
6 12 21

You might also like