-->
Showing posts with label WAP to transpose a matrix/array of order mxn.. Show all posts
Showing posts with label WAP to transpose a matrix/array of order mxn.. Show all posts

WAP to transpose a matrix/array of order mxn.

//WAP to transpose  a matrix/array of order mxn.
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("before transpose\n");             // message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("after transpose\n");             // for transposed matrix
for(i=0;i<total_col;i++)
{
  for(j=0;j<total_row;j++)
       {
        printf("%d",matrics_1[j][i]);    // display of matrix with trasnposed elemnts
       }
       printf("\n");
}     
getch();
}
------------------------------------------------------------------------------------------
using codeblocks/devc++  with return concept
---------------------------------------------------------------------------------------
//WAP to transpose  a matrix/array of order mxn.
#include<stdio.h>
int main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("before transpose\n");             // message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("after transpose\n");             // for transposed matrix
for(i=0;i<total_col;i++)
{
  for(j=0;j<total_row;j++)
       {
        printf("%d",matrics_1[j][i]);    // display of matrix with trasnposed elemnts
       }
       printf("\n");
}


 return 0;       
}

-------------
change the rows to column and vice versa.