How to transpose rows into columns and columns into rows in
a multi-dimensional array?

Answers were Sorted based on User's Feedback



How to transpose rows into columns and columns into rows in a multi-dimensional array?..

Answer / sarath

We Have a predefined method for transposing Matrix i.e
TRANSPOSE().


for ex: We have one Matrix called 'A'

A is the array | 0 -5 8 -7 |
| 2 4 -1 1 |
| 7 5 6 -6 |
Transpose the columns and rows of A.
RES = TRANSPOSE( A )
The result is | 0 2 7 |
| -5 4 5 |
| 8 -1 6 |
! | -7 1 -6 |

Is This Answer Correct ?    21 Yes 5 No

How to transpose rows into columns and columns into rows in a multi-dimensional array?..

Answer / raji

int [,]array=new int[2,2] {{1,2},{3,4}};

transpose of the array is

for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
Console.Write("{0} ",a[j,i]);
}
}

o/p : 1 3
2 4

Is This Answer Correct ?    20 Yes 7 No

How to transpose rows into columns and columns into rows in a multi-dimensional array?..

Answer / venugopal

//Here 'i' indicates for 'i'th row and 'j' indicates
for 'j'th row
//Thus, the matrix is iXj with 3X2 size
//The result matrix should be 2X3

//The logic is as fallows

for(int j=0;j<2;J++)
{
for(int i=0;i<3;i++)
console.write(a[j,i]);
//After completing the first row it should be in the
next line
console.writeln("\n");
}

The final out put should be

2 1 3
2 2 4

Is This Answer Correct ?    8 Yes 3 No

How to transpose rows into columns and columns into rows in a multi-dimensional array?..

Answer / vinod rawal

using System;
using System.Collections.Generic;
using System.Text;

// C# code for Transpose Of Matrix (C Sharp) ( Dot net)



namespace TransposeOfMatrix

{

///

/// Summary description for Class1.

///

class Class1

{

public static Class1 cs;

public static int s=0,m=0;

///

/// The main entry point for the application.

///

[STAThread]

static void Main(string[] args)

{

//

// TODO: Add code to start application here

//

int [,]a=new int[10,10];

cs=new Class1();

Console.Write("Enter the order of First Matrix : ");

s=int.Parse(Console.ReadLine());

Console.Write("- ");

m=int.Parse(Console.ReadLine());

Console.WriteLine();

Console.WriteLine("\nEnter The value of First Matrice:");

cs.matrice(a,s,m);

Console.WriteLine("Matrix entered is:\n");

cs.arrange(s);

cs.arrange(a,s,m);

cs.arrange(s);

Console.WriteLine("Transpose of Matrix is :\n");

cs.transpose(a,s,m);

Console.ReadLine();

}

public void matrice(int [,]c,int k,int l)

{

for(int i=0;i<=k-1;i++)

{

for(int j=0;j<=l-1;j++)

{

c[i,j]=int.Parse(Console.ReadLine());

}

}

}

public void arrange(int [,]c,int k,int l)

{

for(int i=0;i<=k-1;i++)

{

for(int j=0;j<=l-1;j++)

{

Console.Write(c[i,j]+"\t");

}

Console.WriteLine();

}

}

public void transpose(int [,]c,int s,int m)

{

int [,]d=new int[10,10];

for(int i=0;i<=s-1;i++)

{

for(int j=0;j<=m-1;j++)

{

d[j,i]=c[i,j];

}

}

cs.arrange(s);

cs.arrange(d,m,s);

cs.arrange(s);

}

public void arrange(int x)

{

for(int i=0;i<=x;i++)

{

Console.Write("----------");

}

Console.WriteLine();

}

}

}

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More C Sharp Interview Questions

What is public void in c#?

0 Answers  


About multi level and multiple inheritance how to achieve in .net ?

2 Answers   CTS, MMTS,


How do you restrict the type which can be used in custom generic?

1 Answers   IBM,


WHICH IS THE BEST BOOK FOR A BEGINNER TO LEARN AP.NET 3.5, C#.NET & ALL THE FEATURES OF VISUAL STUDIO2008? WHAT ARE THE CERTIFICATIONS IN THIS FIELD? WHICH IS BEST BOOK FOR CLAERING CERTIFICATION EXAM? PLZ HELP ME YAAR

1 Answers  


Explain the steps to create satellite assembly?

0 Answers  






What do you mean by string objects are immutable?

0 Answers  


What is as keyword in c#?

0 Answers  


Did it possible to cast a generic type of derived class to generic type of base class?

2 Answers   TCS,


What are annotations in c#?

0 Answers  


What are the types of access modifiers?

0 Answers  


We cannot create instances of static classes. Can we have constructors for static classes?

0 Answers  


What Is The Difference Between ViewState and SessionState?

1 Answers   Fiserv,


Categories