int max int new int for int GetLength for int GetLength Console Write

 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
int max=0;
int[,] C = new int[3, 3] { { 1, 2, 5 }, { 6, 4, 8 }, { 6, 9, 4 } };
for (int i = 0; i < C.GetLength(0); i++)
{
for (int j = 0; j < C.GetLength(1); j++)
{
Console.Write("{0}\t", C[i, j]);
}
Console.WriteLine();
}
int tmp = 0;
int jmax = 0;
Console.WriteLine();
for (int i = 0; i < C.GetLength(0); i++)
{
max = 0;
jmax = 0;
for (int j = 0; j < C.GetLength(1); j++)
{
if (C[i, j] > max)
{
max = C[i, j];
jmax = j;
}
}
Console.WriteLine(max);
tmp = C[i, jmax];
C[i, jmax] = C[i, 0];
C[i, 0] = tmp;
}
Console.WriteLine ();
for (int i = 0; i < C.GetLength(0); i++)
{
for (int j = 0; j < C.GetLength(1); j++)
{
Console.Write("{0}\t", C[i, j]);
}
Console.WriteLine();
}