Write a program to find out transpose of a matrix


Default
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Write a program to find out transpose of a matrix

 
#include
int main(){
     int row_size,col_size,i=0,j=0;
     printf("Enter Matrix row size:");
     scanf("%d",&row_size);                 // matrix row size input from user
     printf("Enter Matrix column size:");  
     scanf("%d",&col_size);                 // matrix column size input from user
     int matrix[row_size][col_size];
    
     // user input for matrix elements
     printf("Enter Matrix Elements");
     for(i=0;i<row_size;i++){
             for(j=0;j<col_size;j++){
                     scanf("%d",&matrix[i][j]);
             }
     }
      
     // transpose of a matrix
     int output[row_size][col_size];
     for(i=0;i<row_size;i++){
            for(j=0;j<col_size;j++){
                     output[i][j] = matrix[j][i];
            }
     }
     // printing output matrix
     printf("Transpose of input Matrix is:\n");
     for(i=0;i<row_size;i++){
            for(j=0;j<col_size;j++){
                     printf("%d ",output[i][j]);
            }
            printf("\n");
     }
}

No comments:

Post a Comment