answersLogoWhite

0


Best Answer

Sorry to delete the previous version of this program, but this one is much more concise and sophisticated. I have written this program for a 3*3 matrix, but if you want to change it, just enter additional variables to store the order of the matrix and then replace the "3"s of the program with them as needed. It's easy. So here we go:

#include

#include

void swap(int *x,int *y);

main()

{

int i,j,k,m,n;

int matrix[3][3];

printf("Enter the matrix: \n\n");

for (i=0;i<3;++i)

{

printf("\nEnter #%d row: ",(i+1));

for (j=0;j<3;++j)

scanf("%d",&matrix[i][j]);

}

printf("\n\n");

for (j=0;j<3;++j)

{

for (i=0;i<3;++i)

if (i>j)

swap(&matrix[i][j],&matrix[j][i]);

}

printf("The transposed matrix is: \n\n");

for (i=0;i<3;++i)

{

for (j=0;j<3;++j)

printf("%4d",matrix[i][j]);

printf("\n\n");

}

}

void swap(int *x,int *y)

{

int t=*x;

*x=*y;

*y=t;

return;

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

#include<iostream.h>

#include<conio.h>

class A

{

int a[2][2],b[2][2],

x[2][2],y[2][2],

first[2][2],second[2][2],

c,d,e;

public:

void read()

{

y[0][0]=0;

y[1][0]=0;

y[0][1]=0;

y[1][1]=0;

x[0][0]=0;

x[0][1]=0;

x[1][0]=0;

x[1][1]=0;

first[0][0]=0;

first[0][1]=0;

first[1][0]=0;

first[1][1]=0;

second[0][0]=0;

second[0][1]=0;

second[1][0]=0;

second[1][1]=0; cout<<"Enter the value for first matrix : "<<endl;

for(c=0;c<2;c++)

{

for(d=0;d<2;d++)

{

cin>>a[c][d];

}

} cout<<"Enter the value for second matrix : "<<endl;

for(c=0;c<2;c++)

for(d=0;d<2;d++)

cin>>b[c][d]; for(c=0;c<2;c++)

for(d=0;d<2;d++)

x[c][d]=a[c][d]+b[c][d]; for(c=0;c<2;c++)

for(d=0;d<2;d++)

for(e=0;e<2;e++)

y[c][e]+=a[c][d]*b[d][e]; for(c=0;c<2;c++)

for(d=0;d<2;d++)

first[c][d]=a[d][c];

first[c][d]=a[c][d]; for(c=0;c<2;c++)

for(d=0;d<2;d++)

second[c][d]=b[d][c];

second[c][d]=b[c][d];

}

void addition()

{

cout<<"Addition of matrix : "<<endl;

for(c=0;c<2;c++)

{

for(d=0;d<2;d++)

{

cout<<" "<<x[c][d];

}

cout<<endl;

}

} void multiplication()

{

cout<<"Multiplication of matrix : "<<endl;

for(c=0;c<2;c++)

{

for(d=0;d<2;d++)

{

cout<<" "<<y[c][d];

}

cout<<endl;

}

} void transpose()

{

cout<<"Transpose for first matrix : "<<endl;

for(c=0;c<2;c++)

{

for(d=0;d<2;d++)

{

cout<<" "<<first[c][d];

}

cout<<endl;

}

cout<<"Transpose for second matrix : "<<endl;

for(c=0;c<2;c++)

{

for(d=0;d<2;d++)

{

cout<<" "<<second[c][d];

}

cout<<endl;

}

}

}; void main()

{

clrscr();

A a;

a.read();

a.addition();

a.multiplication();

a.transpose();

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

#include <stdio.h> #include <conio.h> void transpose(int a[10][10],int ,int); /*Function prototype*/

void main() { int i,j,m,n; int a[10][10], b[10][10]; clrscr(); printf("Enter the order of matrix a\n"); scanf("%d %d", &m, &n); printf("Enter the elements of matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } printf("Matrix a is\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%3d",a[i][j]); } printf("\n"); } transpose(a,i,j)/*Function call*/ getch(); /* Finding Transpose of matrix*/ void transpose(int a[10][10],int m,int n)/*Function definition*/ for(i=0;i<m;i++) { for(j=0;j<n;j++) { b[i][j] = a[j][i]; } } printf("Its Transpose is\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%3d",b[i][j]); } printf("\n"); } } /*End of main()*/

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

#include<stdio.h>

#include<conio.h>

void main(){

int arr[3][3], arrT[3][3];

int i,j;

clrscr();

printf("Enter the 3x3 matrix:\n");

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

printf("Enter the element arr[%d][%d] : ",i,j);

scanf("%d",&arr[i][j]);

}

}

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

arrT[j][i] = arr[i][j];

}

}

printf("The transpose of the matrix is: \n");

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

printf("\t%d",arrT[i][j]);

}

printf("\n");

}

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

//matrix and its transpose

#include<stdio.h>

#include<conio.h>

void main() {

clrscr();

int m, n, c, d, matrix[10][10],transpose[10][10];

printf("Enter the number of rows and columns of matrix ");

scanf("%d %d",&m, &n);

//storing the elements of matrix

printf("Enter the elements of matrix \n");

for( c = 0 ; c < n ; c++ ) {

for( d = 0 ; d < m ; d++ ) {

scanf("%d",&matrix[c][d]);

}

}

printf("The matrix you have entered is:\n");

for( c = 0 ; c < n ; c++ ) {

for( d = 0 ; d < m ; d++ ) { //m is number of rows

printf("%d\t",matrix[c][d]);

}

printf("\n");

}

//making transpose

for( c = 0 ; c < n ; c++ ) {

for( d = 0 ; d < m ; d++ ) {

transpose[d][c] = matrix[c][d];

}

}

printf("Transpose of entered matrix :-\n");

for( c = 0 ; c < m ; c++ ) {

for( d = 0 ; d < n ; d++ ) { /* after transpose number of rows is equal to no. of columns of original matrix */

printf("%d\t",transpose[c][d]);

}

printf("\n");

}

getch();

}

Output:

Enter the number of rows and columns of matrix 3 2

Enter the elements of matrix

1 2 3 4 5 6

The matrix you have entered is

1 2 3

4 5 6

Transpose of entered matrix:

1 4

2 5

3 6

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include<iostream.h>

int main()

{

int a[3][3];

int tr[3][3];

int i,j;

cout<<"Enter elements of matrix : ";

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

cin>>a[i][j];

}

}

cout<<"original matrix : ";

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

cout<<a[i][j];

}

cout<<"\n";

}

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

tr[i][j]=a[j][i];

}

}

cout<<"\n\ntranspose of matrix : ";

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

cout<<tr[i][j];

}

cout<<"\n";

}

return 0;

}

This answer is:
User Avatar

User Avatar

Programmer

Lvl 2
4y ago

it's just easy to display transpose of matrix. First store the elements of matrix in a[i][j], then display the value of a[j][i] instead of a[i][j]. For more information just visit the below site.

link -

s4sourcecode.online/2020/03/c-program-to-display-transpose-of-matrix.html?m=1

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

for(i=0;i<r;i++)

{

for(int j=0;j<c;j++)

{

b[i][j]=a[i][j];

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in c to find transpose of a matrix using functions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix?

Sp[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Answer]]ell chec[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix&amp;action=edit&amp;section=new|Answer it!]]k your answe[[Q/Discuss:Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Disc]][[help/answering questions|guidelin]]Spell check your answeresussionr[[help/signing in|full benefits]] Save C[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 ]][[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix&amp;action=edit&amp;section=new|Answering 'Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix?']]matrix?ancel[[Q/How many animals are in West Texas|How many animals are in West Texas?]][[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a]][[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a Service workshop?]] Service workshop?[[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a Service workshop?]]More Q&amp;A


How do you write c program to perform sum of elements of matrix using pointers with functions?

i cant write


Write a program to multiply 33 matrix.?

write a program to multily 3*3 matrix.


2x2 matrix multiplication program in 8085 processor?

how to write a program for matrix multiplication in microprocesspr


How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


A c program to square matrix?

A C program to square matrix is a math problem. In the math problem you write down all the outer boundary values of matrix in a circle, then write down the inner value.


Write a c program to find eigenvalue of a matrix?

Yes, do write. That's what you always have to do when you have got a homework-program.


How do you write a java program to find the ad joint of a matrix?

bgfygfrhjyuyhh


Write a program to print the sum of a sparse matrix?

This is a directive, not a question.


Write a C program to find sum of 3 matrices?

matrix


Write a c program for matrix addition using function?

#include&lt;