-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (58 loc) · 1.67 KB
/
Copy pathProgram.cs
File metadata and controls
68 lines (58 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using static System.Console;
namespace MatrixTranspose
{
class Program
{
static void Main(string[] args)
{
// 宣告並建立 A 矩陣
int[,] A = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 },
{ 10,11,12} };
// 宣告並建立 A^t 矩陣
int[,] At = new int[A.GetLength(1), A.GetLength(0)];
// 輸出 A 矩陣
WriteLine("\n=======矩陣 A 元素=======\n");
Print(ref A);
// 轉置矩陣 A
Matrix_Transpose(ref A, ref At);
// 輸出 C 矩陣結果
WriteLine("\n=======轉置矩陣 At 元素=======\n");
Print(ref At);
ReadLine();
}
/// <summary>
/// 輸出矩陣
/// </summary>
/// <param name="matrix"></param>
static void Print(ref int[,] matrix)
{
int i;
int j;
for (i = 0; i < matrix.GetLength(0); i++)
{
for (j = 0; j < matrix.GetLength(1); j++)
Write(matrix[i, j] + "\t");
WriteLine();
}
}
/// <summary>
/// 轉置矩陣方法
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
/// <param name="C"></param>
static void Matrix_Transpose(ref int[,] A, ref int[,] At)
{
int i, j;
for (i = 0; i < A.GetLength(0); i++)
{
for (j = 0; j < A.GetLength(1); j++)
At[j, i] = A[i, j];
}
}
}
}