用C#解决一道数据库题目,求人用代码详细解答。 5
1个回答
展开全部
给你个例子,你看看
private static void MatrixTransposition()
{
int[,] matrixA = new int[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } };
int m = matrixA.GetLength(0);
int n = matrixA.GetLength(1);
int[,] matrixB = new int[n, m];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
matrixB[j, i] = matrixA[i, j];
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
Console.Write(matrixB[i,j]);
Console.Write(" ");
}
Console.WriteLine();
}
}
private static void MatrixTransposition()
{
int[,] matrixA = new int[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } };
int m = matrixA.GetLength(0);
int n = matrixA.GetLength(1);
int[,] matrixB = new int[n, m];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
matrixB[j, i] = matrixA[i, j];
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
Console.Write(matrixB[i,j]);
Console.Write(" ");
}
Console.WriteLine();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询