-->
Showing posts with label WAp to find transpose of a matrix. Here. Show all posts
Showing posts with label WAp to find transpose of a matrix. Here. Show all posts

WAp to find transpose of a matrix. Here , pass matrix as parameter.

in turboc++
--------------------------------------------------------------------------------------------------------
//WAP to transpose  a matrix/array of order mxn.
#include<stdio.h>
#include<conio.h>
void tran_matrix(int array[100][100],int row,int col);//fucntion prototype
int main()
{
int matrics_1[100][100];              //matrix declaration of max size 100x100
int i,j;
int total_row,total_col;             //declaration of variable
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
        }
}
tran_matrix(matrics_1,total_row,total_col);//function calling
getch();
return 0;
}

void tran_matrix(int array[100][100],int row,int col)
{
    int i,j;
printf("before transpose\n");             // message display
for(i=0;i<row;i++)
{
  for(j=0;j<col;j++)           
       {
           printf(" %d ",array[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("after transpose\n");             // for transposed matrix
for(i=0;i<col;i++)
{
  for(j=0;j<row;j++)
       {
        printf(" %d ",array[j][i]);    // display of matrix with trasnposed elemnts
       }
       printf("\n");
}   
getch();
}
-------------------------------------------------------------------------------------------
in codeblocks:-
-----------------------------------------------------------------------------------------------------
//WAP to transpose  a matrix/array of order mxn.
#include<stdio.h>
#include<conio.h>
void tran_matrix(int array[100][100],int row,int col);//fucntion prototype
int main()
{
int matrics_1[100][100];              //matrix declaration of max size 100x100
int i,j;
int total_row,total_col;             //declaration of variable
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
        }
}
tran_matrix(matrics_1,total_row,total_col);//function calling
return 0;
}

void tran_matrix(int array[100][100],int row,int col)
{
    int i,j;
printf("before transpose\n");             // message display
for(i=0;i<row;i++)
{
  for(j=0;j<col;j++)           
       {
           printf(" %d ",array[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("after transpose\n");             // for transposed matrix
for(i=0;i<col;i++)
{
  for(j=0;j<row;j++)
       {
        printf(" %d ",array[j][i]);    // display of matrix with trasnposed elemnts
       }
       printf("\n");
}   
getch();
}