ProAnswers.org

Write a C program to transpose of a Matrix using Function ?

 #include<stdio.h>

#include<conio.h>

#include<string.h>                        

void main()

{

void trans(int,int,int[10][10]);

int i,j,a,b,m[10][10];

clrcsr();

printf(“enter the rows and columns of matrix”);

scanf(”%d%d”,&a,&b);

printf(“enter the elements”);

for(i=1;i<=a;i++)

{

for(j=1;j<=b;j++)

{

printf(“enter m[%d][%d]...”i,i);

scanf(“%d”,&m[i][j]);

}

}

printf(“\n before transpose\);

for(i=1;i<=a;i++)

{

for(j=1;j<=b;j++)

{

printf(“%d\t”,m[i][j]);

}

printf(“\n”);

}

trans(a,b,m);

getch();

}

void trans(inta,intb,intm[10][10])

{

int i,j;

printf(“after transpose”);

for(j=1;j<=b;j++)

{

for(i=1;i<=a;i++)

{

printf(“\t%d”,m[i][j]);

}

printf(“\n”);

}

}

Output:

enter the rows and columns of matrix..3

3

enter the elements

enter m[1][1]=1

enter m[1][2]=2

enter m[1][3]=3

enter m[2][1]=4

enter m[2][2]=5

enter m[2][3]=6

enter m[3][1]=7

enter m[3][2]=8

enter m[3][3]=9

before transpose 1 2 3

4 5 6

7 8 9

after transpose 1 4 7

2 5 8

3 6 9